'Decorator' pattern implemented by extending objects with mixins- need guidance.

Discussion in 'Ruby' started by Asfand Yar Qazi, Dec 1, 2003.

  1. Hi,

    I'm a newb at this language, and now that I've seen it, I think I will
    use it for every project I do from now on (apart from my software 3D
    engine :).

    Anyway, here's the thing: I'm writing a game, and need to implement the
    following behaviour.

    A tree is made of Node objects.

    Each Node can have 0 or more child-nodes (the Node becomes their parent
    node.)

    Each Node can have several Attrs (attributes) attached to it.

    Some Attrs are inheritable, i.e. if a parent node has an inheritable
    Attr, its child nodes do as well. However, not all Attrs are inheritable.

    Attrs should be able to be added and removed dynamically.

    Some Attrs require other Attrs, either from the current node, an
    ancestor node or from a child node. This relationship could be
    compulsory, or optional (in which case the relationship should be
    removed if the relavent Attr is removed from its node.)

    Some Attrs are Singleton Attrs, i.e. they can only exist on one Node in
    a Tree. It should be able to find these Singleton Attrs without having
    to traverse the tree, i.e. their location should be cached in a Hash or
    something.


    I don't know which of Ruby's features are best for implementing this
    behaviour. The Delegate model is nice for the inherited Attrs, however
    not all Attrs are meant to be inheritable.

    Creating attributes as mixins and extending the Nodes with them is a
    good way of adding attributes dynamicallly, but then they can't be
    removed (I think.)

    Just using a Hash and using 'Node.add/remove(Attr)' methods is a
    technique that springs to mind, but I was thinking of a "Ruby" way of
    doing things.

    Any thoughts?




    --
    http://www.it-is-truth.org/
    Asfand Yar Qazi, Dec 1, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean Lutrin
    Replies:
    8
    Views:
    652
    Chris Uppal
    Nov 18, 2004
  2. George Sakkis

    Decorator pattern for new-style classes ?

    George Sakkis, Apr 23, 2005, in forum: Python
    Replies:
    1
    Views:
    318
    Michele Simionato
    Apr 25, 2005
  3. glomde
    Replies:
    5
    Views:
    520
    glomde
    Mar 29, 2007
  4. John Lam

    Mixins for *objects*?

    John Lam, Apr 26, 2005, in forum: Ruby
    Replies:
    1
    Views:
    81
    Austin Ziegler
    Apr 26, 2005
  5. Cris Shupp
    Replies:
    12
    Views:
    252
    Cris Shupp
    Aug 13, 2009
Loading...

Share This Page