ok, you wrote in your post...
$Jason = new SnowBoarder($Jason);
No problem.
so, that "$alex = new OOPMaster( $alex )" was supposed to be funny, I was making a metaphore about how my life could be easier if all I needed to do to learn OOP were writing that statement and voila now I know OOP
PS: maybe u did not get what I meant due to my poor english, if so, excuse me (getting better each time I come here)
My implementation was poor explained in my post. What I would do to represent that a Person has Skills would be:
PHP Code:
class Skill{}
class OopKnowledge extends Skill{}
class Person {
var $skills = array();
function addSkill( &$skill ) {
$this->skills[] =& $skill;
}
}
$person =& new Person();
$person->addSkill( new OopKnowledge() );
In you code you needed to write this:
PHP Code:
abstract class PersonDecorator implements IPerson {
public $wrapper;
function __construct(IPerson &$person) {
$this->wrapper = $person;
}
function gender() {
$this->wrapper->gender();
}
function hasSkills() {
$this->wrapper->hasSkills();
}
}
that made me see that a Decorator actually IS a wrapper for a class, to add some different feature or behavior to the class... My problem is that when I'm designing a solution I hardly see a situation where this pattern fits in, I always think that an aggregation works right. Do you have any example of a real need for the Decorator. Pehaps its a matter of style, I don't know. We can solve a problem with different tools from the toolbox but which problem is solved better with the Decorator.
Bookmarks