Recently, I create a project, Extension Object Pattern Sample, on github. It demonstrates Extension Object Pattern in C++. Extension Object Pattern is to anticipate that an object’s interface needs to be extended in the future. Additional interfaces are defined by extension objects. This pattern is introduced by Erich Gamma. For more detail, see his paper, The Extension Objects Pattern.
The sample code is used in a presentation of CSE776 Design Pattern, Syracuse University.
This sample is a Visual Studio 2010 project, including five projects, discussing the skeleton and implementation issues.
A skeleton of Extension Object Pattern.
Demostrate how to implement Runtime Type Information to identify extensions.
The discussion is in the “Implementation/Identifying extensions” section of Gamma’s paper.
Demostrate how to deal with the situation concrete subject doesn’t known its concrete extensions.
The deisscussion is in the “Implementation/Internal vs. Extenal extensions” section of Gamma’s paper.
Demostrate a solution to control extension objects lifetime by using reference counter.
The discussion is in the “Implementation/Freeing Extension Objects” section of Gamma’s paper.
A sample of how Extension Object Pattern works.