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

learn more… | top users | synonyms (1)

16
votes
8answers
25k views

Web Developer interview questions

I read an article today that listed some basic questions about web development: Describe how POST data was submitted to a server by a browser. Explain a number of HTTP status codes (except maybe 404 ...
16
votes
8answers
3k views

Is writing your own Data Access / Data Mapping Layer a “good” idea?

We're currently in a situation where we have a choice between using an out-of-the-box object-relational mapper or rolling our own We have a legacy application (ASP.NET + SQL Server) where the ...
16
votes
8answers
2k views

Is Dependency Injection worth it outside of UnitTesting

Given a constructor that will never, ever, have to use any different implementations of several objects that it initializes, is it still practical to use DI? After all, we might still want to unit ...
16
votes
5answers
3k views

When would polling for events be better than using observer pattern?

Are there scenarios where polling for events would be better than using the observer pattern? I have a fear of using polling and would only start using it if someone gave me a good scenario. All I can ...
16
votes
2answers
5k views

What are the drawbacks to the ActiveRecord pattern?

I'm curious what are the drawbacks to using the ActiveRecord pattern for data access/business objects. The only one I can think of off the top of my head is that it violates the Single Responsibility ...
16
votes
10answers
2k views

GoF Design Patterns - which ones do you actually use? [closed]

I'm trying to educate my colleagues in the area of design patterns. Some of the original Gang of Four patterns are a little esoteric, so I'm wondering if there is a sub-group of "essential" patterns ...
16
votes
4answers
5k 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 ...
16
votes
3answers
1k views

Newbie question about Decorator design pattern

I was reading a programming article and it mentioned the Decorator pattern. I've been programming for awhile but without any kind of formal education or training, but I'm trying to learn about the ...
16
votes
3answers
3k views

How to store prices that have effective dates?

I have a list of products. Each of them is offered by N providers. Each providers quotes us a price for a specific date. That price is effective until that provider decides to set a new price. In ...
16
votes
4answers
373 views

Is there a specific design strategy that can be applied to solve most chicken-and-egg problems while using immutable objects?

Coming from a OOP background (Java), I'm learning Scala on my own. While I can readily see the advantages of using immutable objects individually, I'm having a hard time seeing how one can design a ...
16
votes
1answer
691 views

When to use prototypical programming in JavaScript

I've spent a good bit of time developing simple widgets for projects in the following way: var project = project || {}; (function() { project.elements = { prop1: val1, prop2: val2 } ...
15
votes
7answers
3k views

What if I will not use Software Design Patterns? [closed]

What kind of problems may I face, if I won't use Software Design Patterns? Can you tell me about the problems of approaching the design using standard object-oriented techniques?
15
votes
5answers
7k views

What is the difference between all-static-methods and applying a singleton pattern?

I am making a database to store information about the users of my website (I am using stuts2 and hence Java EE technology). For the database I'll be making a DBManager. Should I apply singleton ...
15
votes
5answers
945 views

Is this pattern bad? [duplicate]

I notice that when I code I often use a pattern that calls a class method and that method will call a number of private functions in the same class to do the work. The private functions do one thing ...
15
votes
6answers
1k views

Strategies for avoiding SQL in your Controllers… or how many methods should I have in my Models?

So a situation I run into reasonably often is one where my models start to either: Grow into monsters with tons and tons of methods OR Allow you to pass pieces of SQL to them, so that they are ...
15
votes
2answers
4k views

DDD - Does an aggregate root's repository handle saving aggregates?

I am using a DDD-like approach for a greenfield module of an existing application; it's not 100% DDD due to architecture but I'm trying to use some DDD concepts. I have a bounded context (I think ...
15
votes
2answers
2k views

Equivalent of SOLID principles for functional programming

I've found the SOLID principles quite useful when thinking about object-oriented design. Is there a similar / equivalent set of language-agnostic principles tailored for functional programming?
15
votes
3answers
1k views

Does the state Pattern violate Liskov Substitution Principle?

This image is taken from Applying Domain-Driven Design and Patterns: With Examples in C# and .NET This is the class diagram for the State Pattern where a SalesOrder can have different states during ...
15
votes
2answers
6k views

Relationship between Repository and Unit of Work

I am going to implement a repository, and I would like to use the UOW pattern since the consumer of the repository could do several operations, and I want to commit them at once. After read several ...
14
votes
13answers
3k views

Where is the M in MVC?

I'm trying to refactor my application into MVC, but I'm stuck on the M part. In a database-backed app, the model is implemented in the app code, right? But then, what is in the database -- is that ...
14
votes
14answers
6k views

What would be the best real example to explain the usefulness of Inheritance ? [closed]

When trying to explain the concept of Inheritance in OOP, the common example is often the mammals example. IMHO, this is really a bad example, because it will lead the newbies to use this concept the ...
14
votes
4answers
560 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 ...
14
votes
8answers
3k views

Is the GoF book still the one to read? [duplicate]

Possible Duplicate: Is there a canonical book on design patterns? I'd like to read a design patterns book. GoF for sure is the one to read. But after 15 years is it still valid, I mean ...
14
votes
8answers
434 views

When should complexity be removed?

Prematurely introducing complexity by implementing design patterns before they are needed is not good practice. But if you follow all (or even most of) the SOLID principles and use common design ...
14
votes
9answers
4k views

What should a programmer learn first: Algorithms or Design Patterns? [closed]

I have new junior programmers (new graduates) who just joined my team, some of them do not know much about algorithms and design patterns. I am not sure which one should I teach them first?
14
votes
2answers
3k views

What are the main practices and design patterns every .NET guy should know?

In my brief time as a professional programmer I've seen lots of applications written by programmers who's entire education appears to have been reading the first couple of chapters in a .NET 2.0 book. ...
14
votes
4answers
626 views

Proper Model-View-_____ design

I've been reading up about Model View Controller, Model View Presenter, Model View ViewModel, and so on, and generally, the underlying concept seems pretty simple to understand: keep the pretty ...
14
votes
3answers
7k views

Static factory vs factory as a singleton

In some of my code, I have a static factory similar to this: public class SomeFactory { // Static class private SomeFactory() {...} public static Foo createFoo() {...} public ...
14
votes
3answers
902 views

How can you tell whether to use Composite Pattern or a Tree Structure, or a third implementation?

I have two client types, an "Observer"-type and a "Subject"-type. They're both associated with a hierarchy of groups. The Observer will receive (calendar) data from the groups it is associated with ...
13
votes
8answers
3k views

Does MVC apply only to web

It is almost and instantaneous whenever I talk to developers about Model View Controller (MVC) they say you make a request to a url the server builds a entity (MODEL) and provides you with visual ...
13
votes
9answers
6k views

Are too many if-else statements for validation bad? [duplicate]

From the book Professional Enterprise .Net, which has 5 star rating on Amazon that I am doubting after having a read through. Here is a Borrower class (In C# but it's pretty basic; anyone can ...
13
votes
7answers
2k views

Is there a pattern for a more “natural” way of adding items to collections? [closed]

I think the most common way of adding something to a collection is to use some kind of Add method that a collection provides: class Item {} var items = new List<Item>(); items.Add(new ...
13
votes
2answers
2k views

Does the Decorator Pattern exist in the Java IO classes?

For an assignment, I have to find out which of the Gang of Four design pattern the classes java.io.Reader and its subclasses java.io.PushbackReader, java.io.BufferedReader and java.io.FilterReader ...
13
votes
2answers
1k views

What is a 'good number' of exceptions to implement for my library?

I've always wondered how many different exception classes I should implement and throw for various pieces of my software. My particular development is usually C++/C#/Java related, but I believe this ...
13
votes
1answer
624 views

Does Liskov Substitution Principle also apply to classes implementing an interface?

LSP states that classes should be substitutable for their base classes, meaning that derived and base classes should be semantically equivalent. But does LSP also apply to classes implementing an ...
13
votes
4answers
5k views

success:/failure: blocks vs completion: block

I see two common patterns for blocks in Objective-C. One is a pair of success:/failure: blocks, the other is a single completion: block. For example, lets say I have a task that will return an object ...
13
votes
2answers
14k views

What is a recommended pattern for REST endpoints planning for foresighted changes

Trying to design an API for external applications with foresight for change isn't easy, but a little thought up front can make life easier later on. I'm trying to establish a scheme that will support ...
13
votes
2answers
1k views

Is “Analysis Patterns: Reusable Object Models” Still A Good Book To Use For Its Subject Matter Today?

Is "Analysis Patterns: Reusable Object Models" by Martin Fowler (published 1996) still a good book to use for the content it covers? Are there other good books that cover the same content? Are there ...
12
votes
7answers
609 views

Should universities put more emphasis on teaching their students about design patterns?

While I've heard about design patterns being mentioned in a few courses at uni, I know of only a single course which actually teaches design patterns. In almost all other areas (algorithms, ...
12
votes
8answers
978 views

Algorithm Vs Design [duplicate]

Possible Duplicate: Is it essential to learn algorithms to be a real programmer? This question is, perhaps, related mostly to web developers who, like myself, code enterprise applications ...
12
votes
3answers
3k views

How to avoid “managers” in my code

I'm currently re-designing my Entity System, for C++, and I have a lot of Managers. In my design, I have these classes, in order to tie my library together. I've heard a lot of bad things when it ...
12
votes
4answers
950 views

How to determine whether Design Pattern is implemented correctly?

I am successfully able to scale all my old applications which were not using documented Design Patterns. Whatever pattern it is I don't know. To a large extent, I only felt a need to use simple OOP ...
12
votes
4answers
2k views

Does anyone have a specific example of using the Flyweight Pattern?

I have been studying design patterns and came accross the fly weight pattern. I have been trying to see opportunities to use the pattern in my applications but I am having trouble seeing how to use ...
12
votes
4answers
2k views

What is pattern based programming?

Can somebody explain the obsession with patterns and anti-patterns in programming? I ask because I have absolutely no idea what any of the patterns mean. When faced with a programming task I think ...
12
votes
3answers
2k views

Recommended order for learning design patterns? [closed]

I can't help but notice the amount of design patterns that are out there. Does anyone have suggestions on an order I should learn them in? Or should I pick and choose them at random? The only one I ...
12
votes
2answers
2k views

Differences between Design by Contract and Defensive Programming

Could Designing by Contract (DbC) be a way to program defensively? Is one way of programming better in some cases than the other?
12
votes
2answers
941 views

I should have used a factory method instead of a constructor. Can I change that and still be backwards-compatible?

The problem Let's say I have a class called DataSource which provides a ReadData method (and maybe others, but let's keep things simple) to read data from an .mdb file: var source = new ...
12
votes
2answers
396 views

Looking for some OO design advice

I'm developing an app that will be used to open and close valves in an industrial environment, and was thinking of something simple like this:- public static void ValveController { public static ...
12
votes
3answers
5k views

How do I set up MVP for a Winforms solution?

I have used MVP and MVC in the past, and I prefer MVP as it controls the flow of execution so much better in my opinion. I have created my infrastructure (datastore/repository classes) and use them ...
12
votes
2answers
1k views

Is it better to have separate Create and Edit actions or combine Create and Edit into one?

We are using ASP.NET MVC 2 with a Controller/View Presentation Layer and Model consisting of A Business Logic Layer, Data Access Layer [Stored Procedures and classes/methods to talk to the stored ...