Merge pull request #500 from dmitraver/master

Adds criticism to a Service Locator and Singleton patterns.
This commit is contained in:
Ilkka Seppälä 2016-10-18 21:01:58 +03:00 committed by GitHub
commit a37a29e12b
2 changed files with 13 additions and 0 deletions

View File

@ -33,6 +33,12 @@ improves the performance of application to great extent.
* lookups of services are done quite frequently
* large number of services are being used
## Consequences
* Violates Interface Segregation Principle (ISP) by providing pattern consumers with an access
to a number of services that they don't potentially need.
* Creates hidden dependencies that can break the clients at runtime.
## Credits
* [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2)

View File

@ -36,6 +36,13 @@ Use the Singleton pattern when
* [java.lang.System#getSecurityManager()](http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getSecurityManager--)
## Consequences
* Violates Single Responsibility Principle (SRP) by controlling their own creation and lifecycle.
* Encourages using a global shared instance which prevents an object and resources used by this object from being deallocated.
* Creates tightly coupled code that is difficult to test.
* Makes it almost impossible to subclass a Singleton.
## Credits
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)