[UPHPU] Objected Oriented question
Alvaro Carrasco
alvaro at epliant.com
Mon Sep 17 15:20:45 MDT 2007
Justin Giboney wrote:
> I am trying to wrap my head around object oriented programming, but I
> am having a difficult time trying to figure out how to code something
> like this....
>
> A car manufacturing company makes multiple models of cars (like,
> Toyota: Sienna, Tundra, Camry). Each model has a low end, medium end,
> and high end version. Each version has a set of options it can choose
> from.
>
> Here are my thoughts:
> There are at least two classes here (car and option), but I don't
> know wether to make subclasses of each of the models. Then do I make
> subclasses of each of the models for low, medium, and high end?
>
> I could create an array in each of the subclasses for each of the
> options available, but what if there are a hundred options?
>
> What if an option provides more options (like, if you get leather
> seats, then you can get them heated if you like)?
>
>
I would create these classes:
Car
Option
Configuration
and i would probably not create subclasses for each model (inheritance
is one of many ways to be achieve reuse, and it is usually overused...
look up composition and association)
The car object would probably have methods like:
$car->getLowEndConfiguration(); // returns a configuration object,
configured with the basic options
$car->getMediumEndConfiguration();
etc.
these methods would compose a configuration object that would contain
the options...
I would need more specifics to keep going.
Good luck,
Alvaro
More information about the UPHPU
mailing list