My object model for simulations uses decorators but treats them as if they were melted into the base instance, so syntactically they are more like traits. Also, any particular trait/decorator type manages its own index of all living instances with that trait, for some interesting searches. But they're traits which can be attached and detached at will. I call them 'qualities' but that's just my jargon.

Writing a simulation library with this linguistic feature has a completely different feel to it. The job is more about writing many orthogonal qualities, and using classes just as handy pre-packaged combinations of qualities. If classes are nouns, then qualities are like adjectives. I call it quality-oriented programming.

For example, let's take a "MUD" style simulation (though I've used this for other types of sims):

quality Living; // has a life force quality Anatomical; // has a collection of body parts quality Breathing; // has limited range outside atmosphere quality Mortal; // can die quality Injurable; // can be wounded quality Motivated; // has goals // ... and so on class Item; class Thing is a Massive Palpable Item; class Lifeform is a Living Anatomical Thing; class Animal is a Breathing Mortal Injurable Motivated Emotional Gendered Lifeform; class Mammal is a Visible Viewing Eating Drinking Listening Smelling Smelly Feeling Animal; class Primate is a Wearing Manipulating Gestural Facial Wielding Mammal; class Human is a Sentient Carrying Talking Skilled Primate;

Note here that the qualities carry ALL of the implementation and the class definitions are completely nil. These nil classes just indicate the list of qualities to be attached upon instantiation. Also, there's no problem with removing Vocal from a particularly pesky individual Human for a while, even if she were instantiated with that quality.

I've implemented this mechanism in C++, Java and pure Perl; the pure-perl implementation has the highest overhead of course, but I find it the nicest overall language for developing custom object models.

--
[ e d @ h a l l e y . c c ]


In reply to Re^3: Informal Poll: why aren't you using traits? by halley
in thread Informal Poll: why aren't you using traits? by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.