From: "David A. Black" Date: 2005-11-14T23:48:48+09:00 Subject: Re: Heirarchy Troubles Hi -- On Mon, 14 Nov 2005, CBlair1986 wrote: > Hello all. I've got a somewhat unique problem, I think. I have a list > of classes planned out, with the attributes needed for them and > everything else, but I want to figure out how the classes should relate > to one another, so that I don't need to needlessly repeat myself. That's unique?! :-) > For instance, say I have the classes planned as such: > class Apple > attr_accessor :taste, :type, :flavor, :flesh, ... > end > class Orange > attr_accessor :taste, :type, :flavor, :peel, ... > end > and so on. > > How would I go about fitting these together, so that I could have more > general classes such as Fruit and Vegetable and so on? You could encapsulate the non-shared behaviors (or even the shared ones, if you wanted) in modules: module Peelable attr_accessor :peel end module Fleshy attr_accessor :flesh end class Fruit attr_accessor :taste, :type end class Apple < Fruit include Fleshy end class Orange < Fruit include Peelable end etc. That way, if you had more than one peelable class, and the nature of peelability changed, you could change it all in one place. David -- David A. Black dblack@wobblini.net