Posted by iavian on 10/14/07 12:34
<?php
interface Pizza {
public function getPrice();
}
class Margherita implements Pizza {
private $cost = 4.50;
public function getPrice(){
return $this->cost;
}
}
class withExtraTopping implements Pizza{
private $cost = 0.50;
private $pizza;
public function __construct(Pizza $pizza){
$this->pizza = $pizza;
}
public function getPrice(){
return $this->cost + $this->pizza->getPrice();
}
}
$pizza = new Margherita();
$topping1 = new withExtraTopping($pizza);
$total = $topping1->getPrice();
print $total;
?>
Need a couple of lines of code that would generate a margherita pizza
with two extra toppings from the classes above, and print out the
total cost of the pizza?
But how to create a pizza with 2 toppings ??
Navigation:
[Reply to this message]
|