14.4 New Forms of Design Patterns

Ru-Brd

The new form of static polymorphism leads to new ways of implementing design patterns. Take, for example, the bridge pattern , which plays a major role in C++ programs. One goal of using the bridge pattern is to switch between different implementations of an interface. According to [DesignPatternsGoV] this is usually done by using a pointer to refer to the actual implementation and delegating all calls to this class (see Figure 14.3).

Figure 14.3. Bridge pattern implemented using inheritance

graphics/14fig03.gif

However, if the type of the implementation is known at compile time, you could use the approach via templates instead (see Figure 14.4). This leads to more type safety, avoids pointers, and should be faster.

Figure 14.4. Bridge pattern implemented using templates

graphics/14fig04.gif

Ru-Brd


C++ Templates
C++ Templates: The Complete Guide
ISBN: 0201734842
EAN: 2147483647
Year: 2002
Pages: 185

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net