Callbacks in C++

dual purpose class (only if you have to)


You need a single class to fill one of two mutually exclusive roles where the role is determined at the time of construction.




forces resolved:

design rationale:

Unions are a classic C way of overloading functionality into a single structure. Since C++ allows inheritance and polymorphism, most reasons for why you would want to go this route instead of splitting the class or structure into multiple classes or structures are eliminated. This pattern is here more as a reminder that this technique should rarely be used. This technique is most likely to be useful when creating an abstract data type that must be implemented using a family of classes.

[View/Add Comments]

Callbacks in C++
Copyright © 1996-2000 Paul Jakubik
Created: 26 July 1996. Last update: 26 November 2000.