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

Dependency Injection for beginners

David Frame
February 04, 2016

Dependency Injection for beginners

Slides for my talk at the 16th PHP Belfast Meet-up.

David Frame

February 04, 2016

More Decks by David Frame

Other Decks in Technology


  1. Dependency Injection
    David Frame of 31interactive

    View Slide

  2. ?

    View Slide

  3. Scenario #1
    We need to be able to test our
    order class without sending
    any emails!

    View Slide

  4. Dummy mailer class with
    a send() method that
    does nothing!

    View Slide

  5. What is dependency

    View Slide

  6. View Slide

  7. Single Responsibility Principle
    a class should have only a single responsibility
    Open / Closed Principle
    “software entities … should be open for extension, but
    closed for modification.”
    Liskov Substitution Principle
    Interface Segregation Principle
    Dependency Inversion Principle
    one should “Depend upon Abstractions. Do not depend
    upon concretions.”

    View Slide

  8. Scenario #2
    We need to store emails in the
    database so they can be
    queued up and sent at a later

    View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. Dependency
    Injection Containers

    View Slide

  13. View Slide

  14. Thanks for listening!
    Any questions? :)
    Email: [email protected]
    Twitter: @DaGrFr
    Review this talk at https://joind.in/16984

    View Slide