External Polymorphism
By: C. Cleeland, D.C. Schmidt
Allow classes that are not related by inheritance and/or have no virtual methods to be treated polymorphically.
- Decorator [Gamma+95] dynamically extends an object transparently without using subclassing and assumes that the classes it adorns are abstract (i.e., having virtual member functions in C++) that are overridden by a Decorator. Because a Decorator is derived from the class it adorns, it must define all the methods it inherits. This pattern adds polymorphism to concrete classes having nonvirtual methods, letting you define just the polymorphic methods.
- Adapter [Gamma+95] converts an interface to something expected by a client. External Polymorphism extends interfaces so similar functionality may be accessed polymorphically. This pattern creates an entire class hierarchy outside the scope of the concrete classes.
Published in: C++ Report, Sept. 1998
Pages: 28-43
Category: Structural
Summary: Allow classes that are not related by inheritance and/or have no virtual methods to be treated polymorphically.
Url: http://www.cs.wustl.edu/~schmidt/report-art.html