Initialization Via Construction of the Singletree

There are many advantages to including all singletons within a single root object, the singletree, not least of which is that the constructor call graph controls the order of initialization. Under the more widely used approach of static variables, singletons are bound via multiple definitions scattered over multiple files, and there is no straight forward approach to controlling, or even knowing, the sequence of singleton construction. Applying the singletree pattern eliminates the global, class, and local static variables that infest most programs, and allows the designer to restrict access to global state.

For a system such as the shim where the sources follow this singletree pattern, there is a singleton inclusion hierarchy, Figure 9.2, and related constructor call graph that correspond closely to the stages of program initialization. For the shim, the overall construction of the Shim object breaks down into five steps, first the four constructor calls of: the components singleton, § C.1.1; program constants, § 9.1.1; IoFlow object, § 9.1.2; and Router object, § 9.1.3; followed by initialization procedures, IoFlow::init() and Router::init(), § 9.1.4, called from the Shim constructor itself.

Figure 9.2: The upper nodes of the graph of singletons (unshaded), and related wrapper and factory classes (shaded). Edges flow generally from left to right. The IoFlow and Router objects are the primary application domain data members of the Shim object.

Bill Pippin 2010-01-14