views:

317

answers:

10

Wikipedia has a good summary about the various design patterns. Which ones have you used at most in practice and what are your experiences? When should one go for a pattern and when not ?

Edit: A cool C# based link with practical DP examples ( tnx to Mladen Mihajlovic)

+2  A: 

Well the one pattern which I use for most of my projects is MVC. It had proven to be perfect for my type of programming. I've also used a combination of most of the patterns that are available considering the amount of programming I actually do. Don't forget that patterns are "solutions to common problems" that we experience in programming.

Here's a cool link for reading about patterns with implementations (in C# and VB.NET).

Mladen Mihajlovic
+12  A: 

You should definitely avoid "Pattern Driven Design" where you try to cram as many patterns as possible into your classes. I find it useful to know the most important design patterns and when I come across a new design problem I ask myself the question "Do I know a pattern that can be useful here?". If I do then I try to use it; if not then I don't (I also sometimes look them up for I don't know every pattern by heart).

Design patterns can really help you to improve your code but used wrongly they can also really mess things up.

Benedikt Eger
+1 - See a design problem then see what patterns could help solve it. Easier to see problem areas if you are familiar with what different patterns try to solve.
Preet Sangha
+1  A: 

Factories and Decorators are used a lot in both Java and .Net frameworks.

Brian Rasmussen
+3  A: 

My experience is that most programmers who talk about DP do not understand one bit of the forces etc. around it! To quote Yegge in his great Singleton Considered Stupid :

If they claim expertise at Design Patterns, and they can ONLY name the Singleton pattern, then they will ONLY work at some other company.

robi
+2  A: 

As Benedikt already wrote, as a rule of thumb, only use patterns to solve problems, don't change your problem to make it fit to a pattern. ;-)

I use factories and builders a lot. Command, Observer and Visitor patterns on the behavioural side.

They naturally fit in most problems I am encountering in my daily development life.

Patrick Cornelissen
+2  A: 

I think the best rule to try to follow, is KISS. Patterns are useful in helping your software be more maintainable and understandable, but ultimately KISS to ensure that people who may not have experience with all the patterns will be able to understand what your code is doing.

JH
+4  A: 
salgo60
+1 for Head First: Design Patterns reference
Ikke
A: 

We try to identify where well known patterns can be applied. Normally we do not write code for them, we just take it from different places. Tipically we use existing code for Singleton, Proxy, State, etc.

take a look at Gamma's Book "Design Pattern"

The "Java Camp Code" has also code for common patterns (http://www.javacamp.org/designPattern/)

also the Wikipedia has code for patterns

Luis

Luixv
+1  A: 

Answering the title: "What practical experiences...?", I'd say that trying out DP's has taught me how OO really works, especially the power of interfaces.

Answering the rest of the posts:

My favourite patterns are:

  • MVP (Passive View for testing)
  • Strategy -- in combination with TDD,
  • Template method -- for extracting common behaviour into superclasses.

After having used a variety of patterns, I notice that I see them emerge "spontaneously" more and more as answers to some problems.

I agree with others that you should not use patterns for the sake of using patterns -- you'll get stuck trying to shape the problem to fit the solution, which is often problematic.

Lennaert
Hmm. Make that messages, instead of interfaces. Take a look at smalltalk to see how OO really works :)
Stephan Eggermont
+1  A: 

From my experience, some design patterns are more suitable for some type of programming than others e.g, In games programming, the State Machine pattern is what I use alot. MVC and the Template design patterns are also very useful.

sayjava