Separate Logic into Abstract Classes

Video loading...

Join Drupalize.Me to watch this video

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

Log in Sign up
  • 0:03
    To get our ships, we use ShipLoader which queries the database
  • 0:08
    and creates Ship objects. This query for ships goes out, selects all the ships,
  • 0:14
    and then later it is passed to this nice createShipFromData function down here.
  • 0:19
    This is the one we've been working in that creates the objects.
  • 0:24
    Step one, query the database.
  • 0:27
    Step two, turn the data into objects.
  • 0:31
    Suppose that we have a new requirement.
  • 0:34
    Sometimes we're going to get the ship data from the database,
  • 0:38
    but other times it will come from a different source like a JSON file.
  • 0:42
    In the resources directory, there's a new ship.json file.
Loading ...

Separate Logic into Abstract Classes

Loading...

In this tutorial, I will show you how to handle new requirements for data storage by creating two smaller abstract classes out of our original data storage class. By creating these new abstract classes, we can build more flexibility into our code.

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