From 9512f3ec701a8236ee2bf07bedd9ff9cb15aa154 Mon Sep 17 00:00:00 2001 From: Dmitry Avershin Date: Mon, 3 Oct 2016 21:59:36 +0200 Subject: [PATCH 1/3] Closes #436. Adds criticism to service locator pattern. --- service-locator/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service-locator/README.md b/service-locator/README.md index 31d82b13f..75a00ca57 100644 --- a/service-locator/README.md +++ b/service-locator/README.md @@ -33,6 +33,13 @@ 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. +* Limits object composability by stopping the clients to specify needed dependencies for different objects instantiation. + ## Credits * [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2) From eea8785a22527899da48c56f64b63aa0db1df1b5 Mon Sep 17 00:00:00 2001 From: Dmitry Avershin Date: Tue, 4 Oct 2016 14:34:01 +0200 Subject: [PATCH 2/3] Fixes #437. Adds criticism to Singleton pattern. --- singleton/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/singleton/README.md b/singleton/README.md index e1bb42a45..38a05349b 100644 --- a/singleton/README.md +++ b/singleton/README.md @@ -36,6 +36,11 @@ 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. + ## Credits * [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612) From b66e8ecef970858e7823e6319ac378ba7fadfaea Mon Sep 17 00:00:00 2001 From: Dmitry Avershin Date: Tue, 18 Oct 2016 14:18:47 +0200 Subject: [PATCH 3/3] Adds more criticism to Singleton pattern. --- service-locator/README.md | 1 - singleton/README.md | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/service-locator/README.md b/service-locator/README.md index 75a00ca57..479c9ed0f 100644 --- a/service-locator/README.md +++ b/service-locator/README.md @@ -38,7 +38,6 @@ improves the performance of application to great extent. * 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. -* Limits object composability by stopping the clients to specify needed dependencies for different objects instantiation. ## Credits diff --git a/singleton/README.md b/singleton/README.md index 38a05349b..4032ffaed 100644 --- a/singleton/README.md +++ b/singleton/README.md @@ -40,6 +40,8 @@ Use the Singleton pattern when * 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