in reply to Class::Trait to the CPAN?
(I'll be digging into the linked PDF and other folks' ideas here to see how I can improve my own model. Thanks!)
My implementations in Java supported runtime attachment and detachment of qualities, but my draft Perl implementation has been a little heavy and inelegant so far.
These are very handy in design of various roleplaying games; you can add the "edible" quality/trait to an object and it now supports the verb 'eat.'
If classes are nouns, qualities/traits are adjectives.
Once you get used to the idea of qualities/traits, your class hierarchy is a lot different: most classes are really just groups of qualities without much to do directly. For example, a typical player-character in a MUD, just after drinking a magical potion, might look like:
class Human is Mammal with Bipedal, Sentient, Inventoried, Skilled, Clothed instance 3453 is Human with Character, Flying, Enchanted
After the flying-potion enchantment wears off, just remove Enchanted, which in turn can remove Flying.
--
[ e d @ h a l l e y . c c ]
|
|---|