We currently have a Singleton class in our application which in the next phase of development will change to a multi-instance. The problem is every class which makes use of it accesses it directly through the exposed static interface. I believe this is a violation of "Push don't pull" law of Jeremy Miller.
I am not an expert in coding but I believe the said change could have been easier if the dependent classes are not aware about the the Singleton class being a singleton. They should only be interacting with an instance of the Singleton class. For dependencies like this, i always design them as much as possible to be injected to the dependent class' constructor.
A good example are some classes which are dependent on configuration settings. I always provide an abstraction layer between the said class and the config files by providing a wrapper class for the configuration settings. This way, i can have a Unit test project without a config file which is the ideal setup in my opinion.
Posted
11-24-2006 7:52 PM
by
jokiz