views:

327

answers:

6

Possible Duplicates:
list of c++ tricks with names
What C++ idioms should C++ programmers use?

After reading books like C++ Primer, Effective C++ and TC++PL I want to learn some important design patterns.

So, what are the famous design patterns that every C++ programmer should know?

+5  A: 

Read the Design Patterns: Elements of Reusable Object-Oriented Software.

CrociDB
This doesn't answer my question.
Prasoon Saurav
@Prasoon Saurav: Yes, it does.
greyfade
I just didn't want the name of a `Design Pattern ` book.
Prasoon Saurav
@Prasoon Saurav: It's not *a* design pattern book. It's *the* design pattern book. It's also called Gang of Four, for its authors.
greyfade
@Greyfade: Ok fine. I have accepted Steve's answer because I think only his answer is `complete` :)
Prasoon Saurav
+3  A: 

I suggest reading Head First Design Patterns. It's a fun read, and you'll learn about a lot of the common design patterns.

Shakedown
+3  A: 

The obvious answer is the Gang-Of-Four patterns from the famous book. These are the same patterns that get listed all over the place.

http://en.wikipedia.org/wiki/Design_Patterns

Beyond that, have a look around Martin Fowlers web site...

http://martinfowler.com/

There's a fair bit on there - the "famous" one is probably "dependency injection". Most others are pretty domain specific, though.

"Mixin layers" can be interesting for C++. A template class takes its own base as a template parameter, so that the template can be used to add the same functionality to many different classes, or as a composition method so that various features can be easily included/excluded for a library. The curiously recurring template trick is sometimes used as well (the original base is the final fully-composed class) so that the various mixin layers can do some degree of "reflection", so that intermediate methods can be defined in terms of fully-composed member types etc. Of course it can be a bit prone to unresolvable cyclic dependencies, if you're not careful.

http://portal.acm.org/citation.cfm?id=505148

Steve314
+2  A: 

In no particular order, the Gang of Four patterns I see & use most are probably the following:

  • Composite
  • Template Method
  • Abstract Factory
  • Singleton (much hated, but everywhere)
  • Visitor
  • Builder
  • Proxy
Drew Hall
+13  A: 

C++-specific ones: RAII and PIMPL.

Michael
Hard to say which of these is most important. PIMPL doesn't get used enough, perhaps because of fears of indirect call overhead and effectively forcing the object onto the heap rather than the stack.
Steve314
A: 

The think pattern. It's a silver bullet.

wilhelmtell
I thought "silver bullets" were the magic solutions where you don't have to think. Not many of those in development.
Steve314