From: Asfand Yar Qazi Date: 2003-12-01T23:02:08+09:00 Subject: 'Decorator' pattern implemented by extending objects with mixins - need guidance. 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/