A design pattern is a general reusable solution to a commonly occurring problem in software design.

learn more… | top users | synonyms (1)

3
votes
4answers
277 views

Using configuration to determine whether to handle exception or bubble it up

On a side project I'm working on I came up with a way of handling exceptions that's adjustable by configuration. So a try/catch block might look like this: try { fileHelper.MoveFile(file, ...
20
votes
2answers
3k views

How to improve upon Bloch's Builder Pattern, to make it more appropriate for use in classes that may be extended and sub-extended many times over?

I have been greatly influenced by Joshua Bloch's Effective Java book (2nd edition), probably more so than with any programming book I've read. In particular, his Builder Pattern (item 2) has had the ...
0
votes
4answers
536 views

What is this design pattern called? [closed]

I have some code: /// <summary> /// Represents Record Locator class /// </summary> public class RecordLocator : IRecordLocator { /// <summary> /// The Record Locator string, ...
4
votes
3answers
596 views

Extension method naming convention [closed]

We are using some utility methods in our company to simplify programming. So we have following string extension: public static bool IsNoE(this string s) { return string.IsNullOrEmpty(s); } ...
0
votes
3answers
169 views

Doesn’t active record violate SRP and OCP?

I have watched the active record classes in our project grow into large, do-it-all classes. When you need anything about a user, for example, you should go to the Person class. While this makes ...
3
votes
4answers
294 views

Testing all combinations

I need to do some performance measurements inside my application. I want to measure, change some parameters, measure again. There are different algorithms I want to test, and there are various ...
10
votes
2answers
487 views

How do you manage config with dependency injection?

I am a big fan of DI/IOC. It is great for handling/abstracting away hard dependencies, and makes life a little easier. However I have a small gripe with it, which I am not sure how to solve. The ...
0
votes
1answer
181 views

Practical Use of Depency Injection (IoC) Container

I am creating a MVC-ish framework in PHP. I am trying to implement a DI Container to allow the creation of controller objects (among others). My MVC framework is pretty typical. Each module (or ...
1
vote
1answer
236 views

Android Data persistence question

I have an android app in which users have sets of items, and each item has about 10 properties. What I do at the moment: items are stored in the server database when the user logs in, I get all the ...
7
votes
3answers
348 views

How to decompose / model a chessboard

As someone new to programming, I am building a chess web application in JavaScript, both for fun and to learn more about design patterns. I keep running into a wall, which is how to decompose the ...
3
votes
2answers
520 views

Choosing the right Design Pattern

I've always recognized the importance of utilizing design patterns. I'm curious as to how other developers go about choosing the most appropriate one. Do you use a series of characteristics (like a ...
0
votes
0answers
79 views

Design of a custom query result array with lazy loading

I have a database that generates a query result array, each position of the array being a hash like object. Since each array item must be mapped into a well defined class, I decided to implement an ...
1
vote
1answer
218 views

ASP.NET MVC SoC when dealing with back end objects (design decision)

I had a discussion with some peers and even some technical leads in the team around this and Im all for the purist MVC approach. Especially when the project is in its infant stages (its easy to ...
0
votes
1answer
89 views

What is the shortcoming of custom factory comparing to generic factory [closed]

I have a factory method as given below public class AutomobileFactory { Dictionary<string, ICar> internalFactory = new Dictionary<string, ICar>(); public AutomobileFactory() { ...
3
votes
2answers
381 views

Design pattern for overlapping actions and animations?

Is there a design pattern for dealing with overlapping UI actions and animations? A few examples: Let's say I have an interactive table row that expands to reveal an extra control when the user ...
3
votes
4answers
257 views

How to handle affinities?

Assume we have an abstract class having several concrete classes which interfaces publish an information under several equivalent forms, with the difference that each class has a preferred form which ...
1
vote
1answer
304 views

Creating a online database creator

I've been thinking of creating an online database creator (think DabbleDB, Zoho Creator, Intuit Quickbase, etc.). I've been thinking of a couple solutions: Have 4 database tables: Tables, Rows, ...
-1
votes
1answer
182 views

Naming convention of getters and setters [closed]

Given a string variable variable, for example, the convention to expose it is: public class SomeClass { public String variable = ""; public String getVariable() {return variable;} public void ...
0
votes
1answer
213 views

Email Content creation | Proper design

Working on an E commerce application where we need to send so many email to customer like Registration email Forget Password Order placed There are many other emails that can be sent, I already ...
0
votes
2answers
143 views

Best way to display domain object summary information efficiently and in an OO way from a large inheritance tree?

I've provided only simplified code as it's more of an abstract design question. So I have many, many nested business/domain event objects, e.g. public class Event { //bunch of properties and ...
4
votes
3answers
307 views

Designing a fitness / weight lifiting routine database

I'd like to create an app similar to Barbell Pro for Android, for practice / interest / educational purposes really. Or even as another example for database purposes, Fitocracy The problem is, I ...
2
votes
1answer
231 views

DI or Factory Pattern ? Both ? or a different apprach?

Lets say we have an abstract class called BaseSwitch, inherited by concrete implementations Switch A and Switch B, Each Switch representing a real-life switch (A telephony tool which among its ...
0
votes
1answer
134 views

Using a variable in a Global context in webapps

In a webapp, I have a scenario where I need some kind of global context (Static like) for few variables, for the current thread only. If there are 3 different concurrent users, then I expect three ...
1
vote
3answers
254 views

Pattern for costly precondition check before acting

Let's say I have a method DoTheThing() which requires the precondition-check CanTheThingBeDone() to return true. The latter method is time consuming as it accesses the database. I'm finding it hard ...
1
vote
4answers
189 views

available methods change with object state

I'm programming a graph object which can be in either a mutable or immutable state. In both states, it has a get method, but only in the mutable state is the set method allowed. The transition occurs ...
1
vote
1answer
103 views

Factory method - when objects need information to get initalized

Lets look on a simple example: assume that I have three classes implemeting IPersonRepository: SQLPersonRepository, WebPersonRepository, InMemoryPersonRepository. I also have PersonRepositoryFactory ...
2
votes
2answers
297 views

Best practice with respect to anonymous classes in UI applications

When working with user interface based Java programs, one way of attaching behaviour to a certain actions (e.g. to a button click) is through the use of anonymous classes. In the example below, the ...
3
votes
3answers
384 views

Why should a builder be an inner class instead in it's own class file?

Many Builder Pattern examples make the Builder an inner class of the object it builds. This makes some sense since it indicates what the Builder builds. However, in static a static type language we ...
0
votes
2answers
167 views

How to remove redundant code that enables button. Or “if” statement

I got probably "micro optimization" problem. I got "History number", "Next Number", "Reset" buttons, as well "label" for text. Every time I click At "Next number" button I would like to show random ...
1
vote
2answers
643 views

Why does java.util.Calendar use static factory methods?

It is considered better to have a separate factory class than having static methods in same class. See this question. But the standard API uses both approaches. Separate factory: ...
3
votes
1answer
319 views

State pattern vs Inheritance

In the following image for the State Pattern from Applying Domain-Driven Design and Patterns: With Examples in C# and .NET I'm trying to persist the SalesOrder entity into the database. Normally I ...
3
votes
3answers
504 views

Why is inheritance only defined at compile-time?

I found this statement from the gang of four's "Design Patterns" particularly odd; for some context, the authors are comparing inheritance versus composition as reuse mechanisms [p. 19]: "...you ...
0
votes
1answer
225 views

Anemic domain models - what sort of methods a domain object might need?

This question might seem strange, but it's something I've faced sometimes. I've been trying to adopt DDD, however I'm always facing the problem of anemic domain models. The problem is that when I ...
1
vote
3answers
222 views

Are design patterns essential for good code? [duplicate]

Are design patterns (e.g. factory pattern, observer, etc...) required to be known to write good code? I often have no idea of what people mean when they talk about inserting pattern name here pattern ...
-1
votes
1answer
473 views

Is this a design pattern?

I have following C# code. It helped me to avoid some code repetition in a good way. The ExecuteQueryGenericApproach<T> method receives a Func generic delegate as argument. The delegated method ...
0
votes
1answer
192 views

Need an OOP pattern or strategy for “pluggable” property

I'm using OOP and MVVM in a WPF c# application. The goal is for the resulting object (data-bound to user interface) to accurately represent a product. One specific area of the product is highly ...
1
vote
1answer
174 views

Notifying multiple listeners

I am building an Android guitar application and I need a way for GuitarString objects to notify multiple listeners that it has just been played. This includes the current Activity and all instances of ...
0
votes
1answer
135 views

detect if a combination of string objects from an array matches against any commands

Please be patient and read my current scenario. My question is below. My application takes in speech input and is successfully able to group words that match together to form either one word or a ...
0
votes
2answers
111 views

How does one design his various architecture/business models?

I'm currently learning about various application design approaches and there's one thing I can't really get my head around. Let's say I have a physical device in my network, an IP surveillance ...
3
votes
1answer
285 views

Loose Coupling Presenter to View in MVP

We work in a Java shop here and our web application uses an implementation of the MVP architectural pattern. Our manager comes from a .NET world, where he has been exposed to the MVVM design pattern. ...
2
votes
2answers
300 views

How to avoid duplication of code related to shared entities in the repository pattern?

I'm building a repository for a large CRM schema that has a high number of relations between entities. Some of the entities are referenced by almost all entities, e.g. Person and Company. Where I ...
1
vote
1answer
137 views

Optimizing mindmaps by finding the least amount of redundancy

When using mindmaps, you order them based on how you think it fits best. So for instance (tab means subtree) requirements dinner food forks spoons breakfast food forks this ...
1
vote
3answers
125 views

How to conceptually consider and implement user interface rules for numerous controls and data inputs?

I have a user interface with numerous controls and data inputs on it. Buttons, text fields, and checkboxes, etc. Imagine the following "rules" exist for a sample UI with 2 of those controls: B2 ...
1
vote
2answers
930 views

Why separate class CommandHandler with Handle() instead of handling method in Command itself

I have a part of CQRS pattern implemented using S#arp Architecture like this: public class MyCommand { public CustomerId { get; set; } // some other fields } public class ...
4
votes
2answers
231 views

Is Convention Over Configuration “Knowledge in the World” or “Knowledge In Your Head”?

In Don Norman's seminal work "The Design of Everyday Things", the author coined the phrases and explains the difference between "Knowledge in the World" and "Knowledge In Your Head"; an example of ...
3
votes
2answers
169 views

What are the advantages of dynamically binding a method to class instance?

I came across Instagram's API client written in Python. In their class InstagramAPI, they bind the methods to a function in bind.py. When called, the function returns an instance of the class ...
14
votes
4answers
539 views

Is it possible to loosely couple an application to its framework?

Let's say I'm developing a web application. My first choice is to use PHP with Fat-Free Framework (F3) and MVC pattern. Next year, I might decide I want to switch to Zend Framework, or maybe even ...
3
votes
2answers
232 views

Help with inheritance hierarchy design

I'm having trouble designing an inheritance hierarchy. In the figure: Base class: This uses the Template Method. Contains core logic/algorithm that calls virtual/abstract methods Derived ...
5
votes
2answers
300 views

Constructor Injection, Single Responsibility and List initialisation

Given the class: public class Foo : IFoo { private IBarRepository repository public Foo(IBarRepository repository) { this.repository = repository } public IList<IBar> Bars { ...
3
votes
1answer
86 views

Development console commands registration

I have a DevelopmentConsole class. I am making functionality to register console commands for the subsystems. I don't want the console to know about them but also I don't want them to contain a debug ...