mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-09 15:36:36 +02:00
Added a sentence defining the benefit or using DI over the singleton pattern
This commit is contained in:
@@ -101,8 +101,9 @@ request lifecycle in a web application. This typically occurs when we have globa
|
||||
class) or a shared resource (such as an event queue).
|
||||
|
||||
You should be wary when using the singleton pattern, as by its very nature it introduces global state into your
|
||||
application, reducing testability. In most cases, dependency injection can (and should) be used in place of
|
||||
singleton objects.
|
||||
application, reducing testability. In most cases, dependency injection can (and should) be used in place of a
|
||||
singleton class. Using dependency injection means that we do not introduce unnecessary coupling into the design of our
|
||||
application, as the object using the shared or global resource requires no knowledge of a concretely defined class.
|
||||
|
||||
* [Singleton pattern on Wikipedia](https://en.wikipedia.org/wiki/Singleton_pattern)
|
||||
|
||||
|
Reference in New Issue
Block a user