24
votes

Which design pattern do you think is the most popular?

5
  • Both, if possible... Sep 24, 2010 at 14:56
  • "switch instead of polymorphism"?
    – mlvljr
    Nov 6, 2010 at 19:55
  • @Bigown: You should then "accept" the answer you liked the most. If you don't like any of the answers, please offer a bounty.
    – Macneil
    Mar 3, 2011 at 21:12
  • 2
    voted to close as not constructive - this is basically a poll. Unless someone has an empirical study to cite, the answers will all be guesses or favorites (or non-favorites) and the votes will reflect personal sentiments. The end result will be a list of design patterns with no depth. Hence, not constructive. Mar 3, 2011 at 21:17
  • @Steven: I'm pretty sure Jay is right with The Big Ball of Mud. :-) Mar 3, 2011 at 22:53

16 Answers 16

39
votes

I'm pretty sure the most common is 'The Big Ball of Mud'. Unfortunately for us all.
http://en.wikipedia.org/wiki/Big_ball_of_mud

3
  • Agree, when you start a new project everything is well structured and documented, but as the deadline approached, it all ends up like a big ball of mud Sep 24, 2010 at 15:52
  • 3
    @Arturo - That's one possible reason. Others: 1) Small project started by inexperienced programmer that is unexpectedly successful, and then grows beyond it's original purpose. 2) The tendency of inexperienced programmers being assigned to maintenance, who then don't have guidance or understanding of the original architecture, so they just hack stuff in, and it gets worse as system ages. 3) The team uses the wrong technology, or a new technology they are unfamiliar with and use it poorly on a new project, and it craters before the deadline :)
    – Jay
    Sep 24, 2010 at 16:06
  • 1
    LOL - if I could add more points to you, I would. Excellent (and sad) observation. Feb 24, 2011 at 15:18
25
votes

MVC and its variations is definitely one of the top design patterns.

1
  • 2
    I was going to say that the OP's question is rather silly (I still believe it is). However, your answer is pretty much right IMO. If there is one pattern (and its variations) that is pretty much used consistently, it is this one. +1 for your good answer. Feb 24, 2011 at 15:15
21
votes

If you're talking about Gang-of-Four design patterns I would have to say Singleton. This is a really sad state of affairs - almost as if programmers hear about the magic of design patterns and then simply stop after the first one.

If you're talking about architectural-style patterns (in other words, design patterns which span multiple classes or layers) I would have to say MVC. A few other popular ones are the repository pattern and service-locator.

7
  • 2
    It's even sadder when you consider many people consider the Singleton an antipattern!
    – RichardOD
    Sep 24, 2010 at 15:28
  • 1
    @RichardOD, sad that people consider it one when it isn't, or sad that people use it when it's an anti-pattern? Sep 24, 2010 at 16:57
  • What I mean is it is sad that is so popular- it seems to be an interview favourite. Last time I was interviewed I was asked how I would code a Singleton, and my response was that I wouldn't I'd use an IoC container like Unity to handle that for me.
    – RichardOD
    Sep 26, 2010 at 14:19
  • @RichardOD - it's not singleton that it is considered an anti-pattern. It is the abuse usage of it that is an anti-pattern. Very few cases actually demand/need singleton, and in environments with containers that control resource granularity, they aren't even needed. When you see a singleton in a modern Java code base, for instance, that's a typically a red flag for an anti-pattern usage (not on the singleton pattern itself.) Feb 24, 2011 at 15:14
  • @Jaco - I would have a different take from you. I think composite, strategy and template (and their multiple reincarnations) have become far, far more prevalent than singleton, specially since we have been focusing on structural composition over inheritance for the last decade or so. Feb 24, 2011 at 15:17
16
votes

Observer

If you've ever used an event. You've used Observer.

1
7
votes

Decorator

Add functionality to an object at runtime through composition. My personal favorite.

Edit: Also Factory is probably one of the most common.

5
votes

Facade

Think of any REST interface like Twitter or the SO APIs. It's hiding a bunch of back end stuff that, at least in twitters case, can be horribly complex.

Do I care which db tables @apklusk's tweets are stored in? And that it has a fast cache? And that @shemnon has such low readership the tweets are always out of memory? That's the magic of the Facade.

5
votes

Strategy Pattern

If you've ever used dependency injection, you've used the strategy pattern.

1
  • Agreed, strategy in addition to template and composite (and their multiple variations and combination.) Feb 24, 2011 at 15:19
5
votes

Why has nobody mentioned the iterator yet? Especially with all the maps that make up complex data structures... its the one I use the most. Or are we talking about patterns that we re-implement?

3
votes

I am surprised no one has mentioned the Factory pattern, in my experience that is one of the most used (and also most abused) of the patterns out there. If not first, probably the singleton should be first, I would have thought this would be a close second.

3
votes

Along with my previous answer, I'm going to add a new one I ran into today from my beast of an inherited project:

Copy/Paste

While debugging I ran into a piece of code calling 2 similarly named functions:

if(x)
   Func1
else
   Func2

Func1 and Func2 had the same parameters. I pulled them out and diffed, and they are 100% the same except for Func1 calls Func3 and Func2 calls Func4. I pulled those out and diffed them. 100% the same, except for 1 line. So a previous programmer decided to copy and paste two 50-line-nested functions, instead of adding a flag parameter, to 2 private functions used in exactly 1 place. It makes me want to cry.

2
votes

Talking about Gang-of-Four design patterns, I can't think of a program that does not use the Observer pattern. Also, as Jaco mentioned, Singleton is highly used too, unfortunately it has become a hammer (any programmer uses it even if it's not completely needed).

3
  • 1
    Funny, but I've never had the need to use a Singleton. If I need someplace to hold global state, I put it in a configuration file and use a normal class to access it. Sep 24, 2010 at 15:01
  • Of course, in those cases it's not needed... what about when you really need one object to do some job, synchronously, and thread safe. Singleton is not just for holding the state of some static variables, it's a real object with real job to do, etc.
    – Cristian
    Sep 24, 2010 at 15:31
  • Only time I've ever seen need for it is database connections. That said, nearly every "Service" (read: similar to factory) class in this project at work is a singleton, stored in the PHP $_SESSION variable.
    – Tarka
    Sep 24, 2010 at 16:16
2
votes

Interpreter

Rarely implemented, often used. XPATH, XSLT, Regex, jQuery selectors, etc.

1
vote

I'm surprised no one has said "Builder" yet. Or "Adapter". They're probably not as exotic as some of the other ones mentioned, but I use them all the time. Factory and Abstract Factory are very common as well (but they're already taken).

1
vote

Specification

I don't think it's listed in the GoF, but I use variations of it all the time.

1
vote

The most frequently used design pattern is, obviously, Spaghetti.

0
votes

At the software design level, I would argue that Composite, Strategy and Template (and to a lesser extend, Factory) are the most widely usage. For the last decade or so we have seen a preference for composition over inheritance when building our systems using a OO design. As a result, combination of the patterns just mentioned play a much more important role than all others IMO.

Architecturally, I'd argue for MVC on the enterprise, and patterns based on state machines on the embedded side of things.

Not the answer you're looking for? Browse other questions tagged or ask your own question.