The Components Singleton

An object also an instance of the single tree pattern has three data members of types Init, Data, and Root, each of which are const values, and only the last of which, root, is available to the parent class via its static member function root().

The data members are defined as values in order to allow cyclical references within the single tree instance constructor.

The second data member, Data, should include all the pure constant singleton objects of the application.

An object is pure const if it is itself const, and all its data members are either values or pure const references. An object is const if it only occurs in const contexts once constructed, that is accessible via a const reference, or as a value within a const context.

Perhaps more simply, a pure const object has no imperative references, and no hidden imperative aliases to itself created during construction. Such an object is also purely functional, that is completely defined during construction.

The first, Init, must set up references to all containers and other stateful objects referred to during data construction. E.g., if Data includes a constant cache to publicly named symbols also stored anonymously in a symbol table, then the empty symbol table must be created by Init, so that it is available when the lookup/insertion is done as the cache copy is looked up. Or, if a stateful derived class mode variable is used to choose among constant values within Data, again that mode object must be set up within Init.

The final data member value, of type Root, is meant to be the root reference to all the singleton objects in the application. It should include references to all the members of Init and Data.

An instance of the singletons class template has three states, as Init, Data, and Root are constructed one by one. It constrains singleton construction to occur in this order, provides a layer of indirection via its parent class to avoid header file coupling, and serves to encourage stratification of singletons by binding pattern, with Init providing the minimal state needed for application domain specific bootstrapping, Data all the pure functional objects that can be defined without runtime input beyond the command line arguments and configuration files, and Root a mixture of new, stateful object references and the simpler data members borrowed from Init and Data.

Bill Pippin 2010-01-14