views:

286

answers:

9

I'm kind of new to the design patterns concept.
C# is my primary programming language. (I use VB from time to time). I don't want to write sloppy code which is inflexible, not extendable and buggy.
Whenever I see a design pattern in action, I enjoy the logic behind it and understand it well, But unfortunately, I'm having trouble implementing them in my projects.

You see, there are a lot of design patterns (120+ I think) and I am sort of lost among them when I want to decide which one to use.
When it comes to use them in action, I have no idea what to choose.
All I get from tutorials are some fairly simple code snippets which is far away from the production environment. except DDD pattern which I have managed to learn it well since There are at least 2 good books and many resources about it.

Now my question:
Is there anywhere that I can find some real samples using various design patterns? At least some "more practical" samples. Do you know anywhere that I can find such books/samples/resources for other patterns as well?
Thanks.

+7  A: 

I still feel like the original gang of four Design Patterns book is the best way to learn this. The focus isn't on using the pattern in a specific language, or a specific place, but really describing why the patterns exist.

Once you truly understand why the patterns exist (not just how they work), using them in your own production code comes naturally.

Reed Copsey
+1, the GoF book is still a must-read.
0xA3
A: 

Read Martin Fowler's Patterns of Enterprise Application Architecture:

http://www.amazon.co.uk/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420

And also Architecting Applications for the Enterprise:

http://www.amazon.co.uk/Microsoft-NET-Architecting-Applications-PRO-Developer/dp/073562609X

Both are good. The latter has some .NET examples of patterns exposed in Martin Fowler's book. Both books explain when is good to use a given pattern.

Adam
A: 

Hi,

There are countless examples on the internet all you have to do is search. As far as books, I would recommend "Design Patterns: Elements of Reusable Object-Oriented Software"

Enjoy!

Doug
+1  A: 

Start with the GoF patterns. ISBN 978-0201633610 Design Patterns: Elements of reusable object-oriented software

Marvin Cohrs
+9  A: 

I'd start with the Head First Design Patterns book. It's not nearly as complicated as some of the other books and is meant to be a learning experience instead of a reference.

Much better for learning from scratch in my opinion. Head First books are pretty good about presenting the material in interesting ways and do a nice job of keeping you interested. This book also tries to tie in each pattern to a pseudo real-life example. Their examples might not be pertinent to what you are working on, but they at least deal with the same types of issues as real world problems (I think the first example deals with writing a duck simulation video game).

Also Head First Design Patterns focuses on cramming your brain with as many patterns as possible so you can recognize when you are in a situation to use one and be well equipped enough to at least get started. This is where a specific reference, such as the GoF book might come in handy.

However, keep in mind that Head First books typically focus on complete beginners. Their books don't make for good learning materials after you reach the intermediate stage in a given topic.

Robert Greiner
+1 A great book for getting started. Makes it much easier to get into the GoF book next, for people new to these topics.
FrustratedWithFormsDesigner
It's funny, everyone seems to agree it's the best book but i never liked the way it was structured.
ken
@ken yeah, it's a little different, that's for sure. Even though it is structured oddly (different than almost any other book, especially technical books) it does, in my opinion, present the material in a much more approachable method than any other design patterns book I've seen to date. They do this by watering the subjects down as much as possible so they are almost trivially easy to understand. However, design patterns is such a tricky topic, that it actually works in this case.
Robert Greiner
Just read the first chapter of head first book. Even though it's kind of different, But I like the way it tries to teach patterns. I'm feeling very more comfortable with patterns now. Thanks.
Kamyar
@Kamyar great, I'm glad it's working for you. Head First books are a little unconventional, but whatever they do, it seems to work. Good luck.
Robert Greiner
I really think that the best approach to explain design patterns is through real examples. For instance, explain what the builder pattern is and how it's used in solving real issues in very popular frameworks such as spring hibernate or .net equivalent. Also different implementation of the same pattern in different language dynamic and static. For example, You can hardly notice at first sight how the builder pattern is used in a language like groovy where it's widely used. That's my two cents :)
ken
A: 

A C#-specific book I have found helpful is:

C# 3.0 Design Patterns

RedFilter
+1  A: 

This website has a good list of classic patterns and other linked subjects with examples : SourceMaking.

PS: I've always been worried about the rights this site has or not to publish this information. The Refactoring part is a copy of the Martin Fowler book, But I've never found any explicit reference.

Matthieu
A: 

Also, this one seems to be a good resource. Anyone tried it?
http://www.dofactory.com/Framework/Framework.aspx

Kamyar
+2  A: 

Understanding of design patterns comes with time and experience. Unless you are very talented, in the beginning you'll probably write code that could be structured more efficiently and you wont even notice. Don't worry about that too much.

The thing with design patterns is learning to see their benefit. The particular shape of a pattern usually has very definite reasons. Learning to use a pattern is easy once you have figured out the reasons why organizing code that way is beneficial. Ask questions, set up hypotheses, experiment and see if you were right.

For reading, I'd suggest Design Patterns Explained and the SourceMaking site Matthieu suggested is also good.

Saul