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
Tweet

More Decks by David Frame

Other Decks in Technology

Transcript

  1. Dependency Injection
    David Frame of 31interactive

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  4. What is dependency
    injection?

    View full-size slide

  5. 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 full-size slide

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

    View full-size slide

  7. Dependency
    Injection Containers

    View full-size slide

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

    View full-size slide