|
The programs Singleton.cc and Singleton.java we showed in Section 11.1 are examples of the Singleton design pattern. This is one of the 23 design patterns described in [21] that provide best-practice solutions for some of the more common problems in object-oriented design. Java implementations of the patterns are presented in [13]. Copy construction in C++ and cloning in Java play central roles in the Prototype design pattern. See [21, 13] for further details.
Static initialization and static destruction explained in Section 11.3.1 place important constraints on the mixing of C++ and C code. If part of your code is in C++ and part in C, you'd be faced with the question of whether to write main in C or in C++. As explained by Meyers [51], it is better to write the main in C++ so that any static data members are properly initialized and destroyed. Meyers also shows how to get around this difficulty if circumstances dictate that the main be written in C. (While we are on the topic of mixing C++ and C, Chapter 10 briefly alluded to the "extern 'C'" directive that must wrap the C headers and the C functions to prevent C function names from getting mangled by the C++ compiler.)
|