C++ Desing patterns.

KBleivik
Site Admin
Posts: 88
Joined: Tue Jan 31, 2006 3:10 pm
Location: Moss Norway
Contact:

C++ Desing patterns.

Postby KBleivik » Fri Feb 13, 2009 3:46 pm

Design patterns is in essence a least common denominator of minimalistic programming. The classic reference on design patterns is:

Design Patterns: Elements of Reusable Object-Oriented Software by ErichGamma, RichardHelm, RalphJohnson, and JohnVlissides (the GangOfFour - GoF) ISBN 978-0201633610 , ISBN 0-201-63361-2 Publisher: AddisonWesley Professional (November 10, 1994).

Understanding design patters can dramatically improve your programmng sklls. The GoF state two important principles of object oriented design:
  1. Program to an interface and not to an implementation.
  2. Favor object composition over class inheritance.

C++ code from that book can be downloaded from Hillside Group's webpage:

Home: http://hillside.net/

C++ Code download: http://hillside.net/patterns/DPBook/Source.html

You shall not overuse inheritance - white-box reuse. Composition - black-box reuse is an alternative to class inheritance. Composition means that objects work together creating complex functionality. Example a class (object) gets access to another class (object) at run time through its constructor and not via class inheritance (at compile time).

So try to balance the mix of class inheritance and composition. That makes your classes more flexible and the class hierarchy simpler.

Conclusion:
Design your interface carefully. As a result the physical implementation will be more efficient and easier to update / refactor to future needs.

Related - On Refactoring C++ Code:
http://www.goingware.com/tips/xmlmemory.html

Other books:
Andrei Alexandrescu Modern C++ Design: Generic Programming and Design Patterns Applied Addison Wesley Professional
ISBN: 0201704315.
Kjell Gunnar Bleivik
Make it simple, as simple as possible but no simpler: | DigitalPunkt.no |

Return to “C++”

Who is online

Users browsing this forum: No registered users and 2 guests