mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
moved texts to README.md
This commit is contained in:
@@ -5,7 +5,7 @@ namespace DesignPatterns\DependencyInjection;
|
||||
/**
|
||||
* class AbstractConfig
|
||||
*/
|
||||
abstract class AbstractConfig implements Parameters
|
||||
abstract class AbstractConfig
|
||||
{
|
||||
/**
|
||||
* @var Storage of data
|
||||
|
@@ -7,7 +7,7 @@ namespace DesignPatterns\DependencyInjection;
|
||||
*
|
||||
* uses array as data source
|
||||
*/
|
||||
class ArrayConfig extends AbstractConfig
|
||||
class ArrayConfig extends AbstractConfig implements Parameters
|
||||
{
|
||||
/**
|
||||
* Get parameter
|
||||
|
@@ -18,15 +18,6 @@ class Connection
|
||||
protected $host;
|
||||
|
||||
/**
|
||||
* Here, Configuration gets injected and Connection will get all that it needs from Configuration
|
||||
* Without DI, the configuration would be created directly in Connection, which is not very good
|
||||
* for testing and extending Connection
|
||||
*
|
||||
* Notice we are following Inversion of control principle here by asking Config to implement
|
||||
* Parameters interface. This decouples our components. We don't care where the sorce of information,
|
||||
* we only care that config has certain methods to retrieve that information. Read more about Inversion
|
||||
* of control <http://en.wikipedia.org/wiki/Inversion_of_control>
|
||||
*
|
||||
* @param Parameters $config
|
||||
*/
|
||||
public function __construct(Parameters $config)
|
||||
|
@@ -4,6 +4,12 @@
|
||||
|
||||
To implement a loosely coupled architecture in order to get better testable, maintainable and extendable code.
|
||||
|
||||
## Usage
|
||||
|
||||
Configuration gets injected and `Connection` will get all that it needs from Configuration Without DI, the configuration would be created directly in Connection, which is not very good for testing and extending `Connection`.
|
||||
|
||||
Notice we are following Inversion of control principle in `Connection` by asking `$config` to implement `Parameters` interface. This decouples our components. We don't care where the source of information comes from, we only care that config has certain methods to retrieve that information. Read more about Inversion of control [here](http://en.wikipedia.org/wiki/Inversion_of_control).
|
||||
|
||||
## Examples
|
||||
|
||||
* the Doctrine2 ORM uses dependency injection e.g. for Configuration that is injected into a Connection object. for testing purposes, one can easily create a mock object of the configuration and inject that into the connection object
|
||||
|
Reference in New Issue
Block a user