Famous design patterns that a C++ programmer should know

C++-specific ones: RAII and PIMPL.


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


Note - "the original base" doesn't mean the original base class that's inhereted from as that would cause an illegal inheritance cycle - it's just a template parameter used to refer to, to access the types/constants/etc in the final result and perhaps for metaprogramming reflection techniques.

I honestly don't know at this point if I was confused when I wrote "base", or just chose a confusing word.