Stategy and Composite - Using C++ Templates for Implementation of Patterns
Originally, templates were introduced to the language in order to express
common structure in form of parameterized types implemented as class templates.
Function templates, in addition, allow expression of common functionality.
Using the template language feature in C++, several patterns as defined
by Gamma et.al. can be implemented using templates instead of inheritance
and virtual functions. Often, classic object oriented runtime polymorphism
can be replaced by a compile time polymorphism, the effect of which is
a considerable gain in runtime performance.
The template technique leaves behind classic object oriented approaches,
and for that reason many C++ programmers do not even consider it as an
alternative. Yet it has been widely used in areas of C++ programming, where
performance is crucial:
-
Foundation libraries such as the Booch components and the STL prove that
the template version of strategy and other patterns are of great value
in practice.
-
Expression templates, based on the idea of the interpreter pattern, speed
up scientific computating considerably, as the Blitz++ library demonstrates.
In this tutorial, the alternative template technique is demonstrated using
the strategy pattern and the composite and interpreter patterns as examples.
The intent is to expand the attendants' set of programming techniques by
another useful mechanism based on template programming. Naturally, the
decision between runtime techniques on the one hand and compile time mechanisms
on the other hand cannot be made without a sound knowledge of the respective
trade-offs. Hence, we will carefully evaluate the respective advantages
and drawbacks. |
|
PREREQUISITES
|
|
Level:
|
intermediate |
Duration:
|
2 - 3 hours |
Prerequisites:
|
Attendants should be familiar with the concept of C++ templates.
Any knowledge of patterns is not required. |
Presented at:
|
C++ World '99
,
Miami, FL, December 1999
DevWeek Europe 2000
, London,
UK, February 2000
Zühlke Forum
,
Zürich, CH, March 2000
TOOLS USA 2000
, Santa
Barbara, CA, August 2000
OOPSLA 2000
, Minneapolis,
MN, October 2000
ROOTS 2001
, Bergen, Norway,
May 2001 |
If you are interested to hear more about this
and related topics you might want to check out the following seminar or
skim through some further reading:
|
|
Seminars
|
Paper
|
|