Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > 'Decorator' pattern implemented by extending objects with mixins- need guidance.

Reply
Thread Tools

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

 
 
Asfand Yar Qazi
Guest
Posts: n/a
 
      12-01-2003
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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
declaration for module methods which need to be implemented Paul Ruby 1 12-14-2007 03:28 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
making objects unassignable "read-only" (especially when extending) Johannes Zellner Python 3 01-18-2006 04:00 PM
need help creating a tree of processes(implemented in C) Jani Yusef C Programming 4 09-24-2004 10:24 AM



Advertisments