views:

352

answers:

11

I was just looking at this question about SQL, and followed a link about DAO to wikipedia. And it mentions as a disadvantage:

"As with many design patterns, a design pattern increases the complexity of the application." -Wikipedia

Which suddenly made me wonder where this idea came from (because it lacks a citation). Personally I always considered patterns reduce to complexity of an application, but I might be delusional, so I'm wondering if this complexity is based on something or not.

Thanks.

+10  A: 

If the person reading the code is aware of design patterns and their concept and is able to identify design patterns in practical use (not just the book examples) then they really do reduce the complexity.

However I've found with a lot of junior developers, which haven't heard much about design patterns or weren't aware of them at all, that they believe their use increases the complexity of the code.

I can understand it: You suddenly have more classes or code to go through to solve what seems to be a simple problem at first. If you're not aware of the benefits of design patterns, hacked solutions always look better.

__grover
+1  A: 

Design patterns increase the code and divide it into multiple parts. If the design pattern and concept is known then it doesn't sound complex but code based on design pattern you don't know then it looks complex.

Bhushan
+5  A: 

Design patterns often lead to additional levels of abstraction around a problem, and if not handled correctly then too much abstraction can lead to complexity.

However, since design patterns provide a common vocabulary to communicate ideas they also reduce complexity and increase maintainability.

At the end of the day it's a double-edged sword, but I can't imagine a situation where I'd avoid using a design pattern...

Sean
A: 

As Grover said, the power of Design patterns is dependent on the ability of programmers to recognize them when they see them. It's like reducing a mathematical problem to a simpler problem, and them solving the simpler one. To someone who doesn't realize this, though, it seems like you've just created another problem.

I think it's always a good idea to document explicitly, using comments and/or descriptive names, when you're using a pattern to solve a problem. This might even educate another programmer who comes across it about the pattern if he wasn't aware of this.

Rik
+2  A: 

There's an infamous disease known as "Small Boy With A Pattern Syndrome" that usually strikes someone who has recently read the GoF book for the first time and suddenly sees patterns everywhere. That can add complexity and unnecessary abstraction.

Patterns are best added to code as a discovery or refactoring to solve a particular problem, in my opinion.

duffymo
A: 

Design Patterns dont increase complexity, it can make things alot easier to read and maintain. It can be harder to new comers to integrate your developer team, but this effort will be benefitial as a whole.

Problem are Design Patterns as a whole, but the its abuse

Nuno Furtado
+1  A: 

I think it depends on the "audience" i.e. the maintaining developers of the code base. If they are design pattern illiterate then yes it can increase complexity, because most things one doesn't understand are "complex".

If the team is design pattern literate, i.e. they understand the basics and understand the premise behind why design patterns are useful (and as important when they're not) then I think they reduce complexity.

After all Computer Science maybe a fledging science but it's got decades of experience under its belt. The chances are somebody has already solved your problem once before. Whether the answer is a design pattern, data structure or algorithm.

I rather like this humorous explanation by Dylan Beattie. I recommend the read (if nothing else to waste five minutes on a Friday morning!)

Ed Blackburn
Awesome blog post!
Robert Gould
+1  A: 

Design Patterns work like algorithms for Object Oriented Programming. Shows you how to put together objects in a meaningful relationship that performs a particular task. So I would say yes they reduce complexity by allowing you to understand the design of the software better. The same way with algorithms in procedural programs.

If I told you that X was using a Linked List with a Bubble Sort it would be a lot easier to following along with what the programmer was doing.

RS Conley
A: 

They should neither increase nor decrease the complexity.

You should always use an appropriate design for your code. This may use common design patterns or not.

The main benefits to design patterns are

  • By learning them you have added more design tools to your toolbox
  • By learning their names, if you use them and put a comment stating the pattern you're using, it helps readers understand your design intent more concisely

When I teach patterns at Hopkins, the two big things I stress are:

  • Patterns are all about Communication of Intent
  • Don't use any of the specific patterns as a Golden Hammer; lock them in your toolbox and only pull them out if it makes sense for your application.
Scott Stanchfield
A: 

In the short term, design patterns will often increase the complexity of the code. They add extra abstractions in places they might not be strictly necessary. However, in the long term they reduce complexity because future enhancements and changes fit into the patterns in a simple way. Without the patterns, these changes would be much more intrusive and complexity would likely be much higher.

Take for example a decorator pattern. The first time you use it, it will add complexity because now you have to define an interface for the object and create another class to add the decoration. This could likely be done with a simple property and be done with. However, when you get to 5 or 20 decoarations, the complexity with a decorator is much less than with properties.

Steve Rowe
+1  A: 

I made some research about this topic in the scope of GoF patterns. I observed OO Metric value fluctuations after the design pattern refactorings, you can check it out using this link.

baris_a