Skip to content

Instantly share code, notes, and snippets.

@recck
Created November 1, 2012 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recck/3994213 to your computer and use it in GitHub Desktop.
Save recck/3994213 to your computer and use it in GitHub Desktop.
Programming in PHP - OOP Write Up
Car and Garage Classes
IDEA:
A Garage of size n can store up to n Cars
A Garage is treated like a stack, where you can push and pop Cars "in" and "out" of your Garage
A Car is treated as an individual that gets stored inside the Garage
The Garage class:
Must be constructed with a name and a size.
The size is the amount of Cars the Garage can hold.
You must be able to print the Garage and the Cars inside the Garage using a magic method.
The Car class:
Must be constructed with a year, make and model.
You must be able to print the Car as a stand alone object using a magic method.
Garage should have the following properties:
name, size, cars
Garage should have the following methods:
a constructor, push (adds a car to the garage), pop (removes the first car [first in, first out]),
and a magic method to print the Garage and the Cars inside
Car should have the following properties:
year, make, model
Car should have the following methods:
a constructor, getYear, getMake, getModel, and a magic method to print the Car as a stand alone object
No variable should be accessed directly, so look into scope!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment