I have recently started learning design patterns. I have understood the basics of few patterns. Now I want to get familiar with some real code examples where these patterns are being utilized. Can somebody here please point out to some open source projects where design patterns are being used ? I would like to see how design patterns are being used in real world code.
-
You can take a look at this similar question: http://stackoverflow.com/questions/5039196/design-pattern-used-in-projects – David Feb 23 '11 at 13:50
-
"If I were king I’d just start beheading people for writing factories that make factories. It’d collectively save us billions of dollars. And every time you make a singleton, God kills a start-up, two if you think you’ve made it thread-safe." [Landon Dyer](http://www.dadhacker.com/blog/?p=1274) – sbi Feb 23 '11 at 18:57
-
I want to thank you all for good references!! And yes, I dp have a feeling that Singletons should be avoided. Can anybody point out how we can rule out singletons ? – cppdev Feb 24 '11 at 07:05
4 Answers
Following are some of the links. JUnit Cookbook provides brilliant example of quite a few patterns - really worth checking.
Hope that helps.

- 4,137
- 6
- 39
- 53
-
-
Yeah - but patterns are more language agnostics - real life examples can come from anywhere. – Nilesh Feb 23 '11 at 14:09
-
@Nilesh: Only if the languages share features. How is he going to learn template metaprogramming patterns or memory management patterns or exception safety patterns? Definitely *not* appropriate. – Puppy Feb 23 '11 at 18:46
-
@DeadMG: Look at the question its very generic and mostly seems centered around GoF Patterns. And moreover he has started learning design patterns now - should he start with the high end patterns? Please be careful when you exercise down votes. – Nilesh Feb 24 '11 at 03:53
-
@Nilesh: The question doesn't mention *any* patterns, or GoF, how could you draw any GoF conclusion from it? The fact is that C++ and Java do not actually share that many language features and have some very different best practices, and Java design patterns are not going to be particularly useful for C++. Moreover, do not insult me by suggesting that I am careless with my downvote. That downvote is my personal discretion. Suggesting that I am wrong in issuing it is one thing, careless is another. What, do you think I downvoted you by *accident* or something? – Puppy Feb 24 '11 at 11:38
-
@DeadMG: The question is tagged under design-patterns tag. If you look at the definition that gets mentioned while posting under this tag - that itself comes from GoF. Most of the ppl who answered here have referred to it as GoF patterns. You seem to be the only one who disagrees. Moreover - I have mentioned this before in my comments that patterns that I have suggested are language agnostics and are not lanugage specific. That is why I was suggesting that look at the question and then my answers (specifcally the links I have mentioned). But you seem to have skipped that before downvoting! – Nilesh Feb 24 '11 at 12:06
Well, this is tooting my own horn a bit, but an Open Source project I'm working on makes extensive use of the factory method pattern. I implement the guts of the pattern itself here as a set of templates, define a factory here, register a subclass for that factory here, and use the factory to instantiate objects here.

- 3,280
- 2
- 21
- 24
IMHO, ACE (Adaptive Communication Environment) can be a good example. It also uses c++ templates with design patterns, which is also pragmatical. This framework takes basis of Pattern-Oriented Software Architecture: Patterns for Concurrent and Networked Objects book, which is also a good reference for design patterns, besides GoF

- 1,902
- 2
- 18
- 28
In the book by GOF which you are probably reading, for each Design Pattern they provide a REAL code example, I mean not the sample code, but they actually say in which projects each DP has been used. Those projects are mostly OpenSource. HTH

- 130,161
- 59
- 324
- 434
-
Be aware that the C++ examples from the GoF book don't represent modern C++ – Nemanja Trifunovic Feb 23 '11 at 13:50