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

learn more… | top users | synonyms (1)

8
votes
6answers
3k views

Why is subclassing too much bad (and hence why should we use prototypes to do away with it)?

I was reading up on design patterns, and I read that the prototype design pattern does away with excessive subclassing. Why is subclassing bad? What advantage would using a prototype bring about over ...
6
votes
3answers
475 views

Is it bad practice for a decorator to break the decoration chain?

I'm currently using decorators to apply various modifications to a template prior to rendering it. I'm unsure about my cache decorator, though, because it is currently able to break the chain of ...
5
votes
4answers
286 views

Type mocking frameworks does not change coding practices from testability point?

Many people recommend that we should code against interfaces and avoid statics for testability. Interfaces are not just for testability, they are sometimes a requirement. But sometimes we introduce ...
5
votes
4answers
276 views

Users creating instances from a template - is there a software pattern that corresponds to this use case?

I am looking into designing a system where users build a template item and then create many instances based on this template.They then need to be able customise each instance but I also need for them ...
1
vote
2answers
162 views

Is there a problem with writing an in-memory DAL for testing the BLL/ViewModels?

Mocking the DAL/Repository that I pass to the BLL/ViewModels for testing purposes is not much different than creating an in-memory DAL. Right now I'm using an in-memory DAL in a new project instead of ...
3
votes
1answer
1k views

Forcing aggregate root child access through the aggregate root alone

Context I'm developing an application using a Domain Driven Design approach. I want to use a design pattern wherever appropriate and apply all SOLID principles. Scenario I have an order and I want ...
4
votes
2answers
3k views

Is this a proper implementation of an iOS MVC pattern?

After browsing the apple docs, I came across this sample of their MVC pattern: Using NSNotificationCenter and without using KVO, would this diagram below represent a correct implementation of the ...
3
votes
3answers
330 views

Designing access to file-based “database”

It happened frequently that I have to provide access to a bunch of files organized in a directory tree according to some (sometimes loosely specified) rules. My standard pattern is to provide a ...
2
votes
2answers
230 views

Extensibility data model pattern

I was wondering how you'd be able to map the following criterias to common design patterns. I use PHP 5.3 and MySQL 5.5 and have my own mvc framework for my company but some parts could be better and ...
11
votes
2answers
352 views

What are the advantages of separating 'result' from 'status'

Let's say you have some automated processes that generally go through the following states; scheduled - initiated - validating - executing - completed On top of that these processes can prematurely ...
60
votes
5answers
13k views

When is it not appropriate to use the dependency injection pattern?

Since learning (and loving) automated testing I have found myself using the dependency injection pattern in almost every project. Is it always appropriate to use this pattern when working with ...
25
votes
4answers
4k views

Why was dependency injection pattern not included in the Gang of four?

Why was the dependency injection pattern not incluided in the gang of four? Did GOF pre-date widespread automated testing? Is dependency injection now considered a core pattern?
9
votes
4answers
409 views

Does an iterator have a non-destructive implied contract?

Let's say I'm designing a custom data structure like a stack or a queue (for example - could be some other arbitrary ordered collection that has the logical equivalent of push and pop methods - ie ...
12
votes
1answer
4k views

Learning Asynchronous programming [closed]

Asynchronous non-blocking event driven programming seems to be all the rage. I have a basic conceptual understanding of what this all means. However what I'm not sure is when and where my code can ...
3
votes
2answers
900 views

What is the advantage of implementing a composite design pattern?

Apparently, a composite design pattern represents individual entities and collective entities in the same manner. What is the advantage to this? For instance, if I subclass a class, why would I want ...
6
votes
1answer
771 views

When business rules affect presentation in MVC

The MVC design pattern is supposed to led itself to separating business rules from presentation. But sometimes business rules AFFECT presentation. What is the best way to deal with this? Is that ...
21
votes
2answers
16k views

Separating data access in ASP.NET MVC

I want to make sure I'm following industry standards and best practices with my first real crack at MVC. In this case, it's ASP.NET MVC, using C#. I will be using Entity Framework 4.1 for my model, ...
6
votes
4answers
265 views

Is there a pattern that will help with this data structure

I'm doing a java project. My main structure contains 2 lists with elements of type A the other type B. B itself contains a list of objects which may contain elements of A. It must be that when an ...
1
vote
3answers
595 views

Effective template system [closed]

I'm building a content management system, and need advice on which theming structure should I adopt. A few options (This is not a complete list): Wordpress style: the controller decides what ...
0
votes
1answer
280 views

How do I maintain states

I have a winforms application with a display window that can show 3d geometry. I have another control on which I have a series of options to turn on/off different items in my display window. However ...
3
votes
1answer
693 views

Using the decorator pattern in a deep class hierarchy

How would one use the Decorator design pattern for anything other than trivial toy problems, in a deep class hierarchy? For example, let's say you have the class class Decorated : public Foo, Bar, ...
5
votes
1answer
332 views

What other patterns can I use for this singleton?

I have a bit of code which uses a plugin and core model, revolving around four major objects: the Core, Server, Logger, and Parser, in slightly particular order. The Core acts as the central factory, ...
34
votes
2answers
16k views

Best practice/Patterns for two way data synchronisation

Quite often in my work the idea of 2-way data synchronisation between database systems crops up. The classic example is two slightly different CRM systems (say, Raiser's Edge and Salesforce) and the ...
3
votes
1answer
2k views

Opensource showcase for MVC in Java Swing [closed]

I've allready created small desktop CRUD applications using Java/Swing. In hindsight I'm not quite sure if the overall design of these applications is good. I've also done some reading on MVC and ...
19
votes
4answers
4k views

How should I add functionality to an object that already exists?

I have an interface that has a certain amount of well-defined functionality. Let's say: interface BakeryInterface { public function createCookies(); public function createIceCream(); } This ...
6
votes
2answers
285 views

God Namespace just as bad as God Object?

We have about 3/4 different projects, each sharing a certain level of data. Some data is not shared, but all the data access has ended up in a single namespace that is included in every project. ...
3
votes
3answers
235 views

Patterns for Maintaining Model State in Real Time

While some platform in some languages already address this issue, I would like to keep this semi-language agnostic and to focus on patterns associated with this issue. I have a data model that ...
4
votes
1answer
616 views

PHP Aspect Oriented Design

This is a continuation of this Code Review question. What was taken away from that post, and other aspect oriented design is it is hard to debug. To counter that, I implemented the ability to turn ...
2
votes
2answers
1k views

Right design pattern to use StopWatch class

I have to measure execution time for a blocks of code. I had implemented simple StopWatch class like http://www.goldb.org/stopwatchjava.html. If I will invoke methods of StopWatch class directly ...
1
vote
1answer
1k views

What is the best design pattern for asynchronous message passing in a Chrome extension?

I have a background script that is responsible for getting and setting data to a localStorage database. My content scripts must communicate with the background script to send and receive data. Right ...
27
votes
8answers
7k views

Are utility classes with nothing but static members an anti-pattern in C++?

The question Where should I put functions that are not related to a class has sparked some debate over whether it makes sense in C++ to combine utility functions in a class or just have them exist as ...
17
votes
4answers
6k views

Mediator vs Observer?

Can someone provide me with a canonical answer on the differences between an Observer and a Mediator, and a summary of when you should use one pattern over the other? I am unsure of what kind of ...
9
votes
4answers
667 views

How can a child state machine relinquish control back to the parent state machine?

My top level state machine has some states and edges. I will call this the parent state machine. A ----> B ----> C Any state within the parent state machine can be a state machine too. I will ...
9
votes
3answers
2k views

Understanding Loose / Tight Coupling in the “Real World”

I wont say what "community" because I want a non-biased explanation, but let's say you're building a reusable module and that module requires 3+ dependent modules and removing 1 of them causes a ...
25
votes
5answers
13k views

What's the best way to build a factory using NInject?

I am pretty comfortable with dependency injection using NInject in MVC3. While working in an MVC3 application, I developed a custom Controller Creation Factory using NInject, so any controller that is ...
2
votes
2answers
372 views

Factory design pattern - getting the types from a table

I've implemented a generic factory as described here I need to register elements to the factory hard-code like this: Factory.Register(1, typeof(MyClass)); this factory will have to be correlated ...
2
votes
2answers
694 views

Who's the author/creator of the Repository Pattern?

I´m pretty sure it´s not the gang of four. I have a feeling this is a newer pattern. Where was it first published/mentioned?
10
votes
4answers
768 views

Literate programming, good/bad design methodology

I have recently found the concept of literate programming. And I found it rather intriguing. Yet I have not been encountered with claims that it is a bad way to structure a program. It seems not ...
4
votes
5answers
1k views

Java - using single class or multiple class for each type?

I currently have a Java class called "node" which has a number of fields. Which fields in the class are used depends on a field called "type". There are close to 10 (this can grow) different types of ...
6
votes
1answer
2k views

Advanced JavaScript design patterns [closed]

I'm looking for books, online resources or suggestions about how to structure big projects or build a framework in JavaScript. I'm not looking for books explaining how inheritance or closures work. ...
1
vote
4answers
632 views

How should I deal with nested compositions?

I came across the following question on a website for interviews: Here are 3 products: table, chair and bench. Product can be of material: wood, metal, and plastic. Design class structures for ...
3
votes
2answers
2k views

How to get OOAD and Design Patterns hands-on experience in C#?

I have read the concepts and practiced some examples on OOAD and Design Patterns. But when I was asked to implement the singleton pattern in a little bit different manner, I was unable to do it and ...
4
votes
3answers
732 views

Can you point me to a nontrivial strategy pattern implementation? [closed]

We are faced implementing a registration workflow with many branches. There are three main flows which in some conditions lead to one another. Each flow has at least four different steps; some steps ...
4
votes
3answers
2k views

How to use a MessageBox using the MVVM pattern?

I am implementing a UI application using the MVVM design-pattern. The thing is, sometimes when you detect that something is wrong with data that was inputted by the user, you'd like to notify him ...
7
votes
5answers
305 views

How to introduce a new pattern into an existing codebase?

In my quest to better my development skills I learn new design patterns. In sample projects or personal projects it's really easy to adapt new patterns into my code. However at work I have a large ...
2
votes
3answers
586 views

design pattern for describing a variable subpart of a config file

Suppose I have an XML config file like the following: <myapp> <settings/> <output> <mailto>mail service configuration parameters</mailto> ...
5
votes
2answers
1k views

Designing web-based plugin systems correctly so they don't waste as many resources?

Many CMS systems which rely on third parties for much of their code often build "plugin" or "hooks" systems to make it easy for developers to modify the codebase's actions without editing the core ...
8
votes
5answers
470 views

Reengineering the project from scratch [duplicate]

Possible Duplicate: When do you rebuild an application or keep on fixing the existing one I am currently working on a project that has been in development for the last few years used ...
23
votes
6answers
3k views

Is there a design pattern that would apply to discount models?

Are there any known design patterns for implementing discount models? By discount models, I mean the following: If a customer buys Product X, Product Y and Product Z he gets a discount of 10% or ...
3
votes
2answers
704 views

Is there a design pattern for modelling job execution flow?

In my application I have a set of jobs to execute: Each job goes through the states "not started", "started", "completed", "failed" etc. Each job has a set of pre-conditions and post-conditions. ...