Learning/Implementing Design Patterns (For Newbies)

OopDesign Patterns

Oop Problem Overview


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)

Oop Solutions


Solution 1 - Oop

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.

Solution 2 - Oop

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 !

Solution 3 - Oop

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

Solution 4 - Oop

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.

Solution 5 - Oop

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.

Solution 6 - Oop

Bruce Eckel has a http://mindview.net/Books/TIPatterns/">book on design patterns, although it's Java, it's like all of his books amazing. And the best thing is, they are free!

Solution 7 - Oop

C# 3.0 Design Patterns for a C# perspective on design patterns.

alt text
(source: oreilly.com)

Solution 8 - Oop

An introductory book that I found useful and well written is Design Patterns Explained by Alan Shalloway and James Trott (Addison Wesley).

alt text

Do not start from the Gang of Four book, for it is not an introductory book by any means.

Solution 9 - Oop

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

Solution 10 - Oop

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

Solution 11 - Oop

Design Patterns      
(source: Amazon)

Solution 12 - Oop

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!

Solution 13 - Oop

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.

Solution 14 - Oop

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

Solution 15 - Oop

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.

Solution 16 - Oop

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

Solution 17 - Oop

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.

Solution 18 - Oop

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.

Solution 19 - Oop

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.

Solution 20 - Oop

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.

Solution 21 - Oop

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.

Solution 22 - Oop

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...

Solution 23 - Oop

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.

Solution 24 - Oop

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).

Solution 25 - Oop

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

Design Patterns in C#

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAshlockeView Question on Stackoverflow
Solution 1 - OopBill the LizardView Answer on Stackoverflow
Solution 2 - OopKeesDijkView Answer on Stackoverflow
Solution 3 - OopLeopold CimrmanView Answer on Stackoverflow
Solution 4 - OopLars A. BrekkenView Answer on Stackoverflow
Solution 5 - Ooppramodc84View Answer on Stackoverflow
Solution 6 - OopJan GressmannView Answer on Stackoverflow
Solution 7 - OopJPrescottSandersView Answer on Stackoverflow
Solution 8 - OopFederico A. RamponiView Answer on Stackoverflow
Solution 9 - OopDavid PikeView Answer on Stackoverflow
Solution 10 - OopamazedsaintView Answer on Stackoverflow
Solution 11 - OopPaul CroarkinView Answer on Stackoverflow
Solution 12 - OopmmiikaView Answer on Stackoverflow
Solution 13 - OopRoyd BrayshayView Answer on Stackoverflow
Solution 14 - OopElieView Answer on Stackoverflow
Solution 15 - OopBill KView Answer on Stackoverflow
Solution 16 - OopKen PennView Answer on Stackoverflow
Solution 17 - OopddaaView Answer on Stackoverflow
Solution 18 - OopskinpView Answer on Stackoverflow
Solution 19 - OopPeter TurnerView Answer on Stackoverflow
Solution 20 - OopSamnangView Answer on Stackoverflow
Solution 21 - OopTimView Answer on Stackoverflow
Solution 22 - OoptoolkitView Answer on Stackoverflow
Solution 23 - OopdongilmoreView Answer on Stackoverflow
Solution 24 - OopUriView Answer on Stackoverflow
Solution 25 - OopDotnetDudeView Answer on Stackoverflow