diff --git a/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Adapter.php b/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Adapter.php index 1477849..a5c8499 100644 --- a/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Adapter.php +++ b/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Adapter.php @@ -23,11 +23,14 @@ class Adapter implements TargetInterface /** * The constructor. + * + * To achieve Dependency Inversion Principle, we need to inject adaptee(s) + * in the constructor of adapter. This is a key feature. */ - public function __construct() + public function __construct(AdapteeA $a, AdapteeB $b) { - $this->adapteeA = new AdapteeA(); - $this->adapteeB = new AdapteeB(); + $this->adapteeA = $a; + $this->adapteeB = $b; } /** diff --git a/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Client.php b/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Client.php index 11c601c..cd2b210 100644 --- a/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Client.php +++ b/src/Whizark/DesignPatterns/GoF/Structural/Adapter/ObjectAdapter/Client.php @@ -5,5 +5,5 @@ require '../../../../../../../vendor/autoload.php'; -$adapter = new Adapter(); +$adapter = new Adapter(new AdapteeA(), new AdapteeB()); $adapter->targetMethod();