views:

877

answers:

13

I've been hearing and reading about cases when people had come across cases of overused design patterns. Ok, missused design patterns are understandable phenomenon. What does it actually mean overused design patterns?

Do you have any examples and why do you think there are too many patterns?

+1  A: 

This was actually discussed by our one and only Jeff Atwood on Coding Horror:

http://www.codinghorror.com/blog/archives/000380.html

Sheehan Alam
+2  A: 

I would say the Singleton is well overused. There are often much better solutions than using what's essentially a global variable.

Rob Hruska
+4  A: 

I guess Singleton gets easily overused (though it certainly has its legitime uses).

Addiction to the Singleton pattern is called Singletonitis. :) Symptoms include, at least, unnecessarily high coupling, and testing becoming more difficult.

Edit: As a prescribed cure for Singletonitis, you could try Inline Singleton, described in Refactoring to Patterns by Joshua Kerievsky.

Edit 2: For a good discussion on Singletons, see this older question: What is so bad about Singletons

Jonik
I thought Singletonitis is inflammation of your Singleton. Surely addiction would be Singletonmania? What some posters here have is Singletonphobia.
Software Monkey
+3  A: 

The singleton pattern, which is only suitable in a very few cases and makes testing harder. It's not only over-used, but it's often badly implemented in Java and C# - people often rush into double-checked locking when it's not only inappropriate but also relatively hard to get right.

EDIT: I really should have realised that everyone would post the same thing.

Next example, the factory pattern and in particular its use in the Java DOM API. Blech.

Jon Skeet
The first time I saw a Java class named SomethingFactoryFactory I thought it was a joke. Alas...
Bill the Lizard
@Bill Reminds me of http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12 :)
Rob Hruska
+1 for factory overuse!
Software Monkey
As ever, downvotes are more useful with comments...
Jon Skeet
I haven't seen a bad implementation of a C# one, as they're all using your code Jon http://www.yoda.arachsys.com/csharp/singleton.html. Actually that's a lie I've seen a C# MVP who didn't use any locking mechanism
Chris S
@Chris: I've seen people with no locking at all, and people using double checked locking without a volatile modifier. All too common in Java... Hopefully the article has had some impact though :)
Jon Skeet
+17  A: 

The singleton is probably the most overused design pattern. I often see it used in many cases when it's out of scope and much more appropriate to directly instantiate objects.

After that, I believe the factory pattern is way overused as a shortcut of instantiating objects, many times without a real need.

Eran Galperin
+millions for factory. I've seen people use the factory method to create text boxes on ASP.NET forms.
Robert S.
PS: It's instantiate, not instance. Instance is a noun, instantiate is the verb form.
Software Monkey
P.P.S. since we are on the pedantry bandwagon, "create" is probably better than both instance (v) and instantiate :-)
Simon
+2  A: 

I'm going to weigh in on the much-overused Singleton. Quite often, developers learn only this one pattern and use it when a static class would be just as effective.

Jekke
what if I'm using a language like Objective-C without static classes?
Graham Lee
A: 

I too vote for Singleton: a global in abstracted clothing.

And Factory, since that makes it easier not to think about how objects are connected together in a given program.

MSN

MSN
+6  A: 

I vote for ActiveRecord.

Many popular data access frameworks use ActiveRecord as the only data access pattern, a sort of one-size-fits-all solution, even though Martin Fowler's book "Patterns of Enterprise Application Architecture" describes several other data access patterns, and details strengths of each pattern and how to decide when to use each pattern.

Bill Karwin
And it gets mapped to SQL anyway, where it's obvious how it underutilizes the expressive power available for manipulating data.
le dorfier
+3  A: 

PREAMBLE: Generally, Singleton is considered the most abused pattern, if for nothing more than the fact that many will use it to write in-line programming in fact, if not in actuality, while others use it as a substitute for global variables.

BODY:There is a book out there called, "A Pattern Language" which predates the illustrious GoF by several years. It calls for a similar language among different aspects of a project — it was apparently a major influence on "Design Patterns" and those who know both texts consider it superior.

My personal experience is that the GoF is only useful in certain circumstances, and a far cry from encompassing all of OOP. I actually find it quite amusing that several of the patterns are made obsolete in other languages, and others are merely redundantly describing the same scenario (Is there really that much difference between something which adapts and translates?)

Patterns, in general, are a good thing. It is good that Singletons generally use a static getInstance method. It is good that many MVC structures use similar naming conventions. On the other hand, Patterns are not everything and that needs to be remembered.

Recommended reading: http://perl.plover.com/yak/design/

Christopher W. Allen-Poole
Great references. I view the difference between Christopher Alexander's patterns and GoF patterns as the difference between describing requirements and describing implementation.
Bill Karwin
I encountered it at about the same time I started really reading the GoF, it gave me a very welcome perspective.
Christopher W. Allen-Poole
+2  A: 

The (sometimes) so-called JavaBeans-Pattern: getters and setters for every field. Highly questionable and extremely widespread.

Fabian Steeg
+5  A: 

Object Orientation, which is no longer a design pattern but a way of life. I have seen a lot of procedural code munged up in objects and a lot of objects for the sake of objects because the zeitgeist says "presumably you are object oriented", when a few lines of C and a struct would do just as well.

I cite it as the most over-ued design pattern because it is (probably) the most widely used design pattern and its merits are rarely questioned.

Simon
+2  A: 

I think a worse problem than overused design patterns is patterns misapplied by enthusiastic developers who've recently learned a new pattern tool and decide they need to try it out. Recently I've been reading some of Misko Hevery's blog (http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/) entries on dependency injection. One of his major assertions is that the singleton pattern implemented as a global instance severely limits testability and should be avoided.

A few days ago I read an interesting opinion on patterns from Christian Gruber's blog. He suggests they are useful as a tool for discussing architectures, but shouldn't be used during design conception lest software architecture deteriorate into what he calls "paint by numbers." See the paragraph on Design Patterns: http://www.geekinasuit.com/2008/12/testability-re-discovering-what-we.html.

So possibly the issue with design patterns is misapplication and tunnel vision induced by the perception that all well designed software must fit into one of the patterns described in Gang of Four.

Ian Will
There's nothing wrong with trying out patterns; the best way to learn is by doing. But it should be done on throw-away code, not as part of a project that actually needs to be deployed.
Bill Karwin
+1  A: 

I keep seeing the Provider pattern used where there is only one provider. This seems like an awful lot of extra work with no benefit.

Jim Anderson