Dependency Inversion Principle

Dependency Inversion Principle

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

0c6fd6a08d0f898159cda7cafcacf07f?s=128

Afnizar Nur Ghifari

April 17, 2017
Tweet

Transcript

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

    Object Oriented Programming Design Principle April 17, 2017
  2. Hello Dependency Inversion Principle April 17, 2017

  3. What’s dependency? Dependency Inversion Principle April 17, 2017

  4. and what’s inversion? Dependency Inversion Principle April 17, 2017

  5. and again what’s principle? Dependency Inversion Principle April 17, 2017

  6. Let’s hear the story Dependency Inversion Principle April 17, 2017

  7. Dependency Inversion Principle April 17, 2017

  8. So, Dependency Inversion Principle is… Dependency Inversion Principle April 17,

    2017
  9. Dependency Inversion Principle April 17, 2017 “High level objects should

    not depend on low level implementations”
  10. Why using Dependency Inversion Principle? Dependency Inversion Principle April 17,

    2017
  11. Implement Dependency Inversion Principle and code example Dependency Inversion Principle

    April 17, 2017
  12. Dependency Inversion Principle April 17, 2017 class PasswordReminder { private

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

    $dbConnection; public function __construct(MySQLConnection $dbConnection) { $this->dbConnection = $dbConnection; } } Low Level High Level
  14. But that’s the bad example Dependency Inversion Principle April 17,

    2017
  15. “Depend on Abstraction not on concretions” Dependency Inversion Principle April

    17, 2017
  16. Dependency Inversion Principle April 17, 2017 class PasswordReminder { private

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

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

    Dependency Inversion Principle April 17, 2017
  19. Dependency Inversion Principle April 17, 2017 interface DBConnectionInterface { public

    function connect(); }
  20. The good example Dependency Inversion Principle April 17, 2017

  21. 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; } }
  22. “Depend on Abstraction not on concretions” Dependency Inversion Principle April

    17, 2017
  23. Conclusion Dependency Inversion Principle April 17, 2017

  24. “Your code which can easily be extended, modified, tested, and

    refactored without any problems. ” Dependency Inversion Principle April 17, 2017
  25. Thank you! Dependency Inversion Principle April 17, 2017