Posted by Thomas Mlynarczyk on 10/14/07 13:42
> But how to create a pizza with 2 toppings ??
I would do something like this:
interface NotForFree { function getPrice(); }
class Pizza implements NotForFree { ... }
class Margherita extends Pizza { ... }
class Topping implements NotForFree { ... }
class CheeseTopping extends Topping { ... ]
class OnionTopping extends Topping { ... }
$pizza = new Margherita;
$pizza->addTopping( new CheeseTopping );
$pizza->addTopping( new OnionsTopping );
$pizza->getPrice();
/* or */
$pizza = new Margherita( new CheeseTopping, new OnionsTopping );
$pizza->getPrice();
Greetings,
Thomas
--
C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
Navigation:
[Reply to this message]
|