From: "Luke A. Kanies" Date: 2004-08-13T11:37:23+09:00 Subject: Relationship between classes Hi all, I think this is a ruby question, as my problem is written in ruby, but it is mostly just a programming question. I have two types of classes, objects and operations. Each object has one or more operation class associated with it (meaning that these are operations which can be executed on the objectgs). When an object instance is created, it is created with one or more attributes, and as many operations as can be successfully run will also be created. For instance, given a File operation, and chmod, chown, and chgrp operations, if I create a File instance with only ownership information, then I can only create an instance of the chmod operation. Now, to the problem: I am have serious difficulty coming up with a good way to store these relationships. It's a one-to-many, in that each object class is related to many operations. It would be easy if I were willing to just let the operations call the objects directly: chmod(file.path, file.owner) # or whatever But because some operations might be associated with more than one object (e.g., chmod would be associated with both Files and Directories), I can't afford to assume that much about the objects. What I want to do is somehow store the association information with the object, like this: ... :chown => [ [:owner, :file], proc { |object| Blink::Operation::Chown.new( :owner => proc { |object| object[:uid] }, :file => proc { |object| object[:file] } ) } ], ... This stores my three key pieces of information: What the object calls the operation (so it knows how to execute it on itself later), what attributes are necessary in order to create an instance of the operation, and how to actuallly instantiate the operation. I am currently storing all of these in a big hash in each object class definition. This seems really inelegant, though, and it causes some weird side effects in my thinking. Is there some better way to store these relationships, without causing leaking of the object interface into the operation definition? Much thanks, Luke -- Commit suicide. A hundred thousand lemmings can't be wrong. --------------------------------------------------------------------- Luke Kanies | http://abstractive.org | http://reductiveconsulting.com