Singleton has become the first example of SW anti-pattern as it can be misused and create hidden dependencies among classes. However even the frameworks supporting dependency injection (one of the most adopted alternative to singleton) use singleton themselves. For instance Google Guice provides a class (Guice) which is a singleton acting as a factory of injectors http://ift.tt/1Bzuaur. Are we then really sure Singleton is that bad and shall be considered an anti-pattern or, as it always happens, there are some cases in which it is bad and some in which it is a necessary and even elegant solution?
Aucun commentaire:
Enregistrer un commentaire