views:

4538

answers:

25

I'm a confused newbie and hobbyist programmer trying to get a grip on this, so forgive me if my question is a little off or doesn't make much sense.

I see a lot of questions on SO revolving around the use of design patterns, and I'm wondering if anyone has a good resources for learning about, and implementing design patterns? I understand the general idea, and know how/when to use a couple of them(Singletons, Factory methods) but I know I'm missing out.

(Just in case it matters, my language of preference is C# but I could learn from examples in other languages)

+54  A: 

Head First Design Patterns

alt text

and the Design Pattern Wikipedia page are the best resources for beginners. FluffyCat is another good, free online resource for design patterns in both Java and PHP.

The Gang of Four book is where to go afterward, but it's fairly advanced, so I'd wait until you have a pretty firm grasp from the other resources.

Bill the Lizard
I second the Head First Design Patterns book. It's great.
Josh Hinman
I second your second!
BQ
I third your second!
Bob Somers
There are C# code examples for Head First Design Patterns available at http://www.msquaredweb.com/DesignPatterns/HeadFirstDesignPatternsInCSharp.zip
toolkit
+1 - this helped me
Pace
I looked at that book...hated it. So I picked up the GoF book and learned all about design patterns from that. It was kind of dry, but much more informative.
Thomas Owens
+1, fantastic book! The rest of the Head First series of books are excellent as well!
mwilliams
@Thomas Owens: I wouldn't recommend GoF to someone who calls theirself a newbie. HFDP is a much gentler introduction.
Bill the Lizard
I initially thought that the head first book was going to be completely nauseating (it's heavy on metaphor, asides, and has a very conversational tone).. but it's actually really inventive and informative; I'm very happy I took the risk and bought it. Imo, choosing gang-of-four = needless masochism.
codeinthehole
I did find the head first book completely nauseating. It spends so much time being "fun" I think it communicates the key ideas poorly - they get lost. Reading it is like watching someon'es dad try to be cool.But the GoF book is the other extreme and thus not for everyone.
Draemon
+1 for Head First Design Patterns. Initially, the 'funny' style they tried to use really irritated me, but it grew on me by the third chapter.Their examples are pretty well laid out, and really try to show why and when to use patterns without burying it all in overly technical talk.
Aaron
The Fluffy Cat site also has the design patterns in php -> http://www.fluffycat.com/PHP-Design-Patterns/
AntonioCS
@AntonioCS: Thanks for pointing out the update to FluffyCat. I updated the answer with new links.
Bill the Lizard
I'm sorry, but I really hate the Head First series, it's too dumbed down for my taste.
voyager
@voyager: The title of the question does explicitly ask for resources "For Newbies."
Bill the Lizard
@Bill: I know, but I agree with the comments of @Thomas and @Draemon. Non programming oriented friends of mine that were recommended this series of books for algorithms of programming classes, hated them and ended up on "drier" books because the amount of information per page was higher. It's only a matter of preference. I've been reading technical books since young age and went to a highly technical high school, that must have made me used to read "dry" books. I prefer books that doesn't have pets talking down to me and sidetracking, but rather plain information for me to assimilate.
voyager
+1 I started reading the excellent GOF book. However this head first design patterns is really cool, I wish I read this first. And best of all, its on line.
01010011
+1  A: 

Patterns of Enterprise Application Architecture (Hardcover) by Martin Fowler

Refactoring to Patterns (Hardcover) by Joshua Kerievsky

Continuous Integration: Improving Software Quality and Reducing Risk (Paperback) by Paul Duval et.al.

Beyond Software Architecture: Creating and Sustaining Winning Solutions (Paperback) by Luke Hohmann

Elie
+17  A: 

I'd add that Design Patterns book from the "Gang of four" is a bible for anyone who is seriously interested in design patterns.

Leopold Cimrman
Or for anyone who wants to tell their programmer friends that they've read the Gang of Four book :)
Dave Markle
+2  A: 
Paul Croarkin
+1  A: 

Design patterns are like any library function, read about them, then when a problem comes up, the design pattern will be in your "Toolchest". There are many design patterns books all patterned after the original "Gang of four" design patters.

For any programmers, I think that and the Refactoring book by Fowler are the absolute minimal requirements.

Bill K
The POSA books were not "patterned after the GOF" book - the GOF happened to be first to be published - they were in production at the same time.
Tim
Just to avoid any confusion, I want to say that MOST design patterns are NOT implemented in a library. Many patterns are formed by combining library classes together.
Bill the Lizard
I did make it sound like they could be done in a library--sorry about that, thanks for the clarification, Bill. Design patterns are generally LIKE libraries but things you can't typically PUT in a library--like different ways that classes unknown to each other interact.
Bill K
A: 

It does not make too much sense to me for someone with very little experience to delve too far deeply into design patterns. It is great to know they exist, but at this point you should focus more on other things rather than just learning about design patterns.

They are useful in context of a problem - as a concept for a new/beginner developer they are really not too much practical value aside form knowing that you should make use of them when and where you can.

EDIT To clarify - many design patterns are a result of problems found in some domains. A new programmer can hardly be expected (IMO) to know the design pattern(s) to use for some set of problems. Just as we get a smattering of algorithms in CS studies, we need an understanding of the things we can do with patterns and their benefits, but when a person is still building hello world or discovering stl there is not much practical need for design patterns. Patterns are great. But they are not the silver bullet.

(Neither was CASE (tools), neither is/was UML, neither is SCRUM, neither is TDD, nor STL, nor Java, nor XML, etc. ) These are all just aspects of our profession and to treat these topics as the second coming is naive.

Tim
But if you don't know about the patterns, you won't know if there's one out there that addresses your particular problem. Yes, as a newbie you are unlikely to NEED a pattern, but it's important to learn the patterns before that need arises.
Elie
I think I covered that in my post...
Tim
You need to have more than just knowing that they exist.... you need to know how they work and the kind of situations where they are used. That's a bit more than superficial knowledge. It may be years before you use a pattern, but when you do, it's not the time to learn the pattern.
Elie
So you're saying a newbie has to learn and understand dozens or more of patterns? What comes off the table in the meantime? I am not arguing against patterns. And I also don't think that learning the specifics of a pattern JIT is a bad thing. Learning patterns before other stuff IMO is not useful
Tim
+1  A: 

For websites, a very good site is http://ajaxpatterns.org, from one of the developers of the ajaxian website

Ken Penn
+1  A: 

The original Design Patterns book is a must-read for all programmers.

It is an excellent book on every level: layout, clarity, insight, depth. It's one of those great books that you first read cover-to-cover, and then use as a reference until you literally know it inside out.

You could start by the Wikipedia page, but treat yourself with the great book too.

ddaa
+6  A: 

My tip:

Read a lot about the patterns from different sources.

Trying to force as many patterns as possible into all the code you're writing as this point is not going to give good results. Instead, let the information rest inside your brain for a while (read: months).

Suddenly you'll find yourself stumbling upon a problem or piece of code and you'll vaguely remember that you've seen something that might work as a solution to this particular problem. Now is the time to look up the details on the pattern you are thinking of and try to apply it.

That's what has worked for me, anyway.

Lars A. Brekken
+5  A: 

Bruce Eckel has a book on design patterns, although it's Java, it's like all of his books amazing. And the best thing is, they are free!

Jan Gressmann
Thanks for the link, didn't realize that was up for free on-line.
James McMahon
+1  A: 

Applying UML and Patterns by Craig Larman. Start from the basic of analysis, design and uses a simple Case scenario. Introduces most of the basic patterns in a simple way.

skinp
A: 

I also suggest having a shufty at Refactoring to Patterns once you've read Head First Design Patterns.

Note: The code examples are in Java, but should be very similar to C# examples...

toolkit
+6  A: 
JPrescottSanders
+1  A: 

If you read about design patterns you'll notice that Java seems to have a few of them implemented.

Look at the source for any framework and you can glean info about design patterns. Personally I don't see them fitting in perfectly to any of my code, sometimes the examples in books and tutorials seem a little idealized, especially for the lone coder.

Design patterns aren't for lazy coders.

Peter Turner
+14  A: 

Design patterns are great for various reasons:

  1. gives you a starting for solving common problems.
  2. gives developers a vocabulary to talk about certain ways of solving problems in a very compact manner.
  3. when working with developers who know design patterns and you use design patterns in your solutions they will understand the solutions a lot faster.

But when your goal is just to learn design patterns I think you are missing the fundamentals. All design patterns are based on more common principles. High Cohesion, Low Coupling Open Closed Principle, DRY, Liskov Substitution Principle etc. For these fundamentals I would read the following books in this order:

  1. Head First Object-Oriented Analysis and Design (Head First) [ILLUSTRATED] (Paperback)
  2. Applying UML and Patterns (Hardcover)
  3. Agile Principles, Patterns, and Practices in C# (Robert C. Martin Series) (Hardcover)

After that you are ready for the basic gang of four design patterns

  1. Head First Design Patterns (Head First) [ILLUSTRATED] (Paperback)
  2. The BIBLE
  3. A nice website (don't buy anything, it is not worth it) http://dofactory.com/Patterns/Patterns.aspx (some implementations of this site are worth a discussion

The next step:

  1. Patterns of Enterprise Application Architecture (Addison-Wesley Signature Series) (Hardcover)
  2. The POSA books

And always remember : the pattern is not the goal !

KeesDijk
I think the fundamentals of OO (encapsulation, inheritance, polymorphism, etc.) are enough to knowledge to start learning design patterns. You can learn the other principles (High Cohesion, Low Coupling Open Closed Principle, DRY, Liskov Substitution Principle, etc.) through learning patterns.
Bill the Lizard
I agree you can learn design patterns with only the fundamentals of OO. But then you make it to the point that you can make a pattern work but not yet fully understand why this is good design, what trade-offs you have made and how you can make variations in the patterns.
KeesDijk
A: 

Patterns comprise the high level vocabulary programmers use to talk about abstract design. If you are reusing an abstract solution, it is helpful to refer to it by name. If you invent a pattern, it is professional to do a little checking to make sure it hasn't already been given a name. If it has been named, then the description may be useful.

After you code even a tiny bit, you will notice yourself writing something similar to what you coded before. This is a pattern. Even if it is a tiny pattern, it is worth noticing. Is there a better pattern? Do you see certain tiny patterns cooperating together to solve a larger problem? Well next time, when you want to solve larger problem, the entire pattern comes into your mind as a single chunk. Fleshing out the detailed lines of code becomes mechanical.

The more you notice patterns, the easier programming becomes, and the more you will appreciate some of the biggest and best patterns worked out by other programmers. Try mastering the MVC pattern. One way or another, variations show up all over the place, even in tiny design decisions.

dongilmore
+2  A: 
Federico Ramponi
+2  A: 

Head First Design Patterns is a good one like others already noted. Besides this, of course the original book and C# Design Patterns. Also there are good websites already mentioned.

Besides self-learning, I seriously recommend starting or attending a pattern study group in your area. See A Learning Guide To Design Patterns for explanation and great order to study the patterns in. We did this and I can honestly say that I would not understand as much as I do now. A weekly meeting with other interested people keeps you surprisingly disciplined when learning something abstract like design patterns.

Happy studies!

mmiika
+3  A: 

I would recommend taking a look at Jean Paul Boodhoo's quintology (?) on Demystifying Design Patterns on DNRtv, urls supplied below. The videocasts touches on Singleton, Abstract Factory among others- the difference being that you can watch him code as he discusses the theory. Good to watch over lunch on a rainy weekday.

http://www.dnrtv.com/default.aspx?showNum=63 http://www.dnrtv.com/default.aspx?showNum=65 http://www.dnrtv.com/default.aspx?showNum=68 http://www.dnrtv.com/default.aspx?showNum=71 http://www.dnrtv.com/default.aspx?showNum=92

David Pike
+1  A: 

For me and my colleagues study Design Pattern that following on Pattern Study Group. They prepare a list of each pattern that we should learn in order and also have the opening questions that make more discussion in group.

Samnang
A: 

Once you understand the concept, go through the Eclipse source code or design, lots of really good examples of these patterns (no surprise, Gamma was one of the designers).

Uri
+3  A: 

An annotation to the above comments.

A Quick Reference For GOF Patterns

Here is a good place you can start dofactory.com/patterns/patterns.aspx - You can find link to each pattern, along with corresponding implementations.

How ever, remember that these are GOF patterns. You might need to read and understand advanced patterns as well, once you gain enough expertise in OOAD. Head First Design Patterns is a good start, and after making some progress, go with Martin Fowler's Enterprise Application Architecture Patterns.

Applying Design Patterns - The Thought Process

Another main aspect - Applying Design patterns is as important as just knowing them. Reading these articles might help you as well.

Applying Design Patterns Part I

Applying Design Patterns Part II

Hope this helps

amazedsaint
A: 

I have found Design Pattern articles on this website really easy to understand

Design Patterns in C#

DotnetDude
+2  A: 

Design Patterns

This tutorial site contains following sub-sections

  • Intent of each design pattern
  • Real World Structure for the design pattern
  • A Problem statement
  • Detailed discussion on the problem
  • Checklist on how to arrive at a pattern
  • Rules of thumb while arriving at pattern.
  • Code snippets for the design pattern which includes C#, C++, Delphi, Java and PHP

This site also contains guide on Anti Patterns, UML and Refactoring.

pramodc84
A: 

Before spending money on books I would recommend Wikipedia's excellent design patterns page. Also for something different Google for "design pattern screencasts" or search for "design patterns" on YouTube. Getting the same information presented differently often helps the penny drop.

The Gang of Four book is the definitive text on the most well known patterns but is not that easy to read and with C++ examples not everyone's favourite.

The Head First Design Patterns text is far more accessible but only contains a subset of the Gang of Four patterns.

The most important thing is to understand where and why a particular pattern is useful. Afterwards search the web for implementation examples in the language of your choice and experiment until you "get it". Understand one pattern before moving on to the next. Everyone understands some patterns better than others (and there are hundreds of lesser known ones).

Just keep plugging away.

Royd Brayshay