From 2a04e3d6ac254b13e3a9d3375a645db430c9043c Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:28:47 +0300 Subject: [PATCH] correct CS --- README.md | 60 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c8e650c..4903917 100644 --- a/README.md +++ b/README.md @@ -1279,6 +1279,7 @@ class Manager { **[⬆ back to top](#table-of-contents)** ### Dependency Inversion Principle (DIP) + This principle states two essential things: 1. High-level modules should not depend on low-level modules. Both should depend on abstractions. @@ -1293,65 +1294,80 @@ the coupling between modules. Coupling is a very bad development pattern because it makes your code hard to refactor. **Bad:** + ```php -class Worker { - public function work() { +class Worker +{ + public function work() + { // ....working } } -class Manager { - /** @var Worker $worker **/ +class Manager +{ private $worker; - - public function __construct(Worker $worker) { + + public function __construct(Worker $worker) + { $this->worker = $worker; } - - public function manage() { + + public function manage() + { $this->worker->work(); } } -class SuperWorker extends Worker { - public function work() { +class SuperWorker extends Worker +{ + public function work() + { //.... working much more } } ``` **Good:** + ```php -interface WorkerInterface { +interface WorkerInterface +{ public function work(); } -class Worker implements WorkerInterface { - public function work() { +class Worker implements WorkerInterface +{ + public function work() + { // ....working } } -class SuperWorker implements WorkerInterface { - public function work() { +class SuperWorker implements WorkerInterface +{ + public function work() + { //.... working much more } } -class Manager { - /** @var Worker $worker **/ +class Manager +{ private $worker; - - public function __construct(WorkerInterface $worker) { + + public function __construct(WorkerInterface $worker) + { $this->worker = $worker; } - - public function manage() { + + public function manage() + { $this->worker->work(); } } - ``` + **[⬆ back to top](#table-of-contents)** ### Use method chaining