Dynamic Traits

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic Traits

John Toohey
Is is possible to apply a Trait to an object after it has been created? I have a situation where I have a collection of object that have been populated from a database, and depending on a typeId property, I would like to apply different Traits to that object. Each Trait would have the same method signatures, but the calculations performs by those methods would be different in each case. 

--
-JT



_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Traits

Damien Cassou
2009/10/26 John Toohey <[hidden email]>:
> Is is possible to apply a Trait to an object after it has been created? I
> have a situation where I have a collection of object that have been
> populated from a database, and depending on a typeId property, I would like
> to apply different Traits to that object. Each Trait would have the same
> method signatures, but the calculations performs by those methods would be
> different in each case.

It's not possible. A design pattern might better suit your needs. Have
a look at State or Strategy.


--
Damien Cassou
http://damiencassou.seasidehosting.st

"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project