On 24. feb.. 2009, at 01.31, Rickard Öberg wrote:

> Ok, but what is the "changing methods at instantiation time" an  
> example
> of? What design pattern is that?
> [...]
> When you say "OO-based" I think that should be "class-based". And  
> being
> class-based is one of the major problems with OOP as it exists today.

OO is all about objects, so objects need to be mass produced in some  
way or another, There are basically two ways of doing this; the  
industrialized way of using classes that serve as blueprints for new  
object instances or object factories that build new instances - or -  
the biological way of building prototype objects that can be cloned.
Most OO-languages use the "industrialized" method, but other  
languages, like JavaScript or Self, are prototype based.
In my JavaScript I clone objects and swap implementations of some of  
the methods to demonstrate the biological way of building.

a_person = new Person();

nancy_cartwright = Object.clone(a_person);
nancy_cartwright.setFirstName("Nancy");
nancy_cartwright.setLastName("Carthwright");

hayashibara_megumi = Object.clone(a_person);
hayashibara_megumi.setFirstName("Hayashibara");
hayashibara_megumi.setLastName("Megumi");
hayashibara_megumi.toString = function() {
        return this.getLastName() + ' ' + this.getFirstName() + '\n';
}

inoue_kikuko = Object.clone(a_person);
inoue_kikuko.setFirstName("Inoue");
inoue_kikuko.setLastName("Kikuko");

japanese_toString = hayashibara_megumi.toString;
inoue_kikuko.toString = japanese_toString;

print(nancy_cartwright);
print(hayashibara_megumi);
print(inoue_kikuko);

You (Rikard) probably don't like the rouge dynamic style of this code,  
and I agree that writing this kind of code is bad for maintainability,  
but for quick disposable solutions, this is "easier" than building a  
big static structure to achieve the same thing.
Whether you like the idea of copying single methods between objects or  
not, the underlying concept here is reuse of fragments, which is one  
of the things Qi4j enables us to do. Qi4j does this in a very  
different way from what one would do in JavaScript or Ruby, but my  
argument is that the concept of fragment composition is more or less  
the same.

BTW; are you (Rikard again :) planning on coming to Oslo anytime soon,  
I really feel that we could have a good discussion of this over a beer  
or five.

Cheers,
Anders


_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to