Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependency Inversion Principle

Dependency Inversion Principle

Dependency Inversion Principle. This was presented during Software Engineering class in Bandung, April 2017.

Afnizar Nur Ghifari

April 17, 2017
Tweet

More Decks by Afnizar Nur Ghifari

Other Decks in Technology

Transcript

  1. Dependency Inversion Principle @afnizarnur / @helmisatria / @knfalah / @miftahulawali

    Object Oriented Programming Design Principle April 17, 2017
  2. Dependency Inversion Principle April 17, 2017 class PasswordReminder { private

    $dbConnection; public function __construct(MySQLConnection $dbConnection) { $this->dbConnection = $dbConnection; } }
  3. Dependency Inversion Principle April 17, 2017 class PasswordReminder { private

    $dbConnection; public function __construct(MySQLConnection $dbConnection) { $this->dbConnection = $dbConnection; } } Low Level High Level
  4. Dependency Inversion Principle April 17, 2017 class PasswordReminder { private

    $dbConnection; public function __construct(MySQLConnection $dbConnection) { $this->dbConnection = $dbConnection; } } Low Level High Level
  5. PasswordReminder class is being forced to depend on the MySQLConnection

    class. Dependency Inversion Principle April 17, 2017
  6. Your class should not care what class you’ll use ✌

    Dependency Inversion Principle April 17, 2017
  7. Dependency Inversion Principle April 17, 2017 class MySQLConnection implements DBConnectionInterface

    { public function connect() { return "Database connection"; } } class PasswordReminder { private $dbConnection; public function __construct(DBConnectionInterface $dbConnection) { $this->dbConnection = $dbConnection; } }
  8. “Your code which can easily be extended, modified, tested, and

    refactored without any problems. ” Dependency Inversion Principle April 17, 2017