Dr. Dobb's Journal September 1998
The Monostate Pattern
Implementation
- Ensuring a unique state for all objects. The crucial step is to declare all data members to be static.
- Mandating local instantiation. Here, the crucial requirement is that no member functions be declared static.
- Subclassing a Monostate class. Implementation of an inheritance hierarchy takes place as for any "ordinary" class and requires no supplementary coding.
Consequences
- Multiple local instantiations but always with only a single state.
- Persistent object state in the absence of any instantiations.
- Familiar syntax. Does not require an accessor function as with Singleton objects.
--S.B. and J.M.C.
Copyright © 1998, Dr. Dobb's Journal