Urban Etter
class Animal { ... }
class Cat extends Animal { ... }
$kitten = new Cat();
$kitten
Cat
// Represents a cat
class Cat {
public $name;
}
// Specification of behaviour 'jump'
interface CanJump {
public function jump();
}
// Implementation of behaviour 'jump'
class FourLeggedJumper implements CanJump {
public function jump() {
...
}
}
class Cat implements CanJump {
// @var CanJump
private $jumper;
public function jump() {
$this->jumper->jump();
}
}
$runner = new FourLeggedJumper();
$kitten = new Cat();
$kitten->setJumper($jumper);
$kitten->jump();
$fourLegs = new FourLeggedJumper();
$twoLegs = new TwoLeggedJumper();
$kitten = new Cat($fourLegs);
$doggie = new Dog($fourLegs);
$ralf = new Human($twoLegs);
if ($forrest instanceof CanJump)
$forrest->jump();