Ok, so I was looking through the GoF Design Patterns book at the store (can't afford to pick it up at the moment - so every once in a while, I go back and read more).
"Favor object composition over class inheritence"
Fair enough.. it explains the pitfalls of inheritence (implementation being bound to compile-time, 'breakage' of encapsulation, tight coupling (thus changes = propogation change issues) etc..
I understand composition (if the 'owner / container' object is destroyed, composite objects go with it). But I'm hazy on delegation and aggregation (not so much from a definition stand point, but from a PHP coding standpoint).
So for example:
class floor {
private $obj;
function __construct(){
$this->obj = new rectangle;
}
function computeArea($x, $y){
return $this->obj->Area($x, $y);
}
}
class rectangle{
private $width, $height;
function Area($a, $b){
$this->width = $a;
$this->height = $b;
return $this->width * $this->height;
}
}
$objTiles = new floor;
echo $objTiles->computeArea(3,5);
How would this composition example be rewritten as deligation and another for aggregation instead?