Object Composition FTW!

Video loading...

Transcripts: 
Transcript language code: 
eng

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:07
    In modern PHP, you're going to spend a lot of time working with other people's classes
  • 0:13
    via external libraries that you bring into your project to get things done faster.
  • 0:18
    Of course, when you do that you can't actually edit their code
  • 0:22
    if you need to change or add some behavior.
  • 0:25
    Fortunately, OO code gives us some really neat ways to deal with this limitation.
  • 0:31
    For the next few minutes, I want you to pretend like our PdoShipStorage
  • 0:35
    is actually from a third-party library,
  • 0:38
    in other words, we can't modify it.
  • 0:41
    Now let's say whenever we call fetchAllShipsData,
  • 0:45
    it's really important for us to log to a file how many ships were found.
Loading ...

Object Composition FTW!

Loading...

In modern PHP, you're going to spend a lot of time working with other people's classes: via external libraries that you bring into your project to get things done faster. Of course, when you do that: you can't actually edit their code if you need to change or add some behavior.

Fortunately, object-oriented code gives us some really neat ways to deal with this limitation. In this tutorial, you'll learn a method called composition in which we'll create a wrapper class, which has some subtle advantages over using inheritance.

Downloads: 
Log in or sign up to download companion files.
Additional resources: