Singletons Encapsulation
Case scenario. Your application is Object Oriented, and requires 3 or 4 specific singletons, even if you have more classes.
Before Example (C++ like pseudocode):
// network infoclass Session { // ...};// current user connection infoclass CurrentUser { // ...};// configuration upon userclass UserConfiguration { // ...};// configuration upon P.C.,// example: monitor resolutionclass TerminalConfiguration { // ...};
One way is to partially remove some (global) singletons, by encapsulating all of them into a unique singleton, that has as members, the other singletons.
This, way, instead of the "several singletons, approach, versus, no singleton at all, approach", we have the "encapsulate all singletons into one, approach".
After Example (C++ like pseudocode):
// network infoclass NetworkInfoClass { // ...};// current user connection infoclass CurrentUserClass { // ...};// configuration upon user// favorite options menuesclass UserConfigurationClass { // ...};// configuration upon P.C.,// example: monitor resolutionclass TerminalConfigurationClass { // ...};// this class is instantiated as a singletonclass SessionClass { public: NetworkInfoClass NetworkInfo; public: CurrentUserClass CurrentUser; public: UserConfigurationClass UserConfiguration; public: TerminalConfigurationClass TerminalConfiguration; public: static SessionClass Instance();};
Please note, that the examples are more like pseudocode, and ignore minor bugs, or syntax errors, and consider the solution to the question.
There is also other thing to consider, because, the programming language used, may affect how to implement your singleton or non singleton implementation.
Cheers.