Singleton Intent

There are really two purposes rolled into a single class for any given implementation of a singleton. The first purpose is clearly the implementation of the Singleton pattern characteristics. The second is the function of the class itself: the behaviors associated with the class modeling the singular resource.

Ordinarily, if we found such a clear duality of purpose in a single class, we would refactor it to separate the concerns. However, the singleton nature suggests that the separate intents live in the same class. The language issues around the behavior of class variables in inheritance hierarchies in most languages prohibit refactoring the singleton nature into a superclass without adding the complexity of a registry. Refactoring to a composition relationship exposes the construction of the class to some degree, contrary to the intent.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.12.232