Skip to content

Commit a37a29e

Browse files
authored
Merge pull request iluwatar#500 from dmitraver/master
Adds criticism to a Service Locator and Singleton patterns.
2 parents 9967786 + b66e8ec commit a37a29e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

service-locator/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ improves the performance of application to great extent.
3333
* lookups of services are done quite frequently
3434
* large number of services are being used
3535

36+
## Consequences
37+
38+
* Violates Interface Segregation Principle (ISP) by providing pattern consumers with an access
39+
to a number of services that they don't potentially need.
40+
* Creates hidden dependencies that can break the clients at runtime.
41+
3642
## Credits
3743

3844
* [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2)

singleton/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ Use the Singleton pattern when
3636
* [java.lang.System#getSecurityManager()](http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getSecurityManager--)
3737

3838

39+
## Consequences
40+
41+
* Violates Single Responsibility Principle (SRP) by controlling their own creation and lifecycle.
42+
* Encourages using a global shared instance which prevents an object and resources used by this object from being deallocated.
43+
* Creates tightly coupled code that is difficult to test.
44+
* Makes it almost impossible to subclass a Singleton.
45+
3946
## Credits
4047

4148
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)

0 commit comments

Comments
 (0)