|
Originally posted by Gerald Davis:
Some time the Mother and Father methods are the same, sometimes they are completely different other times they are neither so you might need couple of IF statement to factor out code that are not the same.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Or you avoid the if statement(s) and do it the *really* OO way:
mother = new Person(new MotherBehaviour());
father = new Person(new FatherBehaviour());
child = new Person(new CompositeBehaviour(new MotherBehaviour(), new FatherBehaviour()));
Of course this only works well if all three instances need the same interface - and it might actually be overkill in simple cases. In other situations, it might well save the maintainability of your system!
Originally posted by Gerald Davis:
I make a terrible habit of resigning my application, so I like to expose the end developer to less objects as possible in this case, only the the Person object.
/** Less verbose way combining mother and father together **/
child = new Person(�Mother,Father�);
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|