From: Curator1 Date: 2008-11-07T23:58:03+09:00 Subject: Re: Ruby's take on S.O.L.I.D. On Nov 6, 11:34 am, Michael Libby wrote: > On Thu, Nov 6, 2008 at 10:38 AM, Curator1 wrote: > > Repeating: Superclasses are based on common conceptual denominators > > (CCD)not on the number of data members. > > Agreed. > > [following code sample shortened for clarity] > > > > > class ClosedPolygon > > end > > > class RegularPolygon < ClosedPolygon > > end > > > class Square < RegularPolygon > > end > > > class Rectangle < ClosedPolygon  # See!!!  CCD's properly > > end > > > class Pentagon < RegularPolygon > > end > > > class IsoTriangle < ClosedPolygon > > end > > > class EquiTriangle < RegularPolygon > > end > > Can we take the principal of common conceptual denominators further by > using modules in addition to superclasses? > > class Rectangle < ClosedPolygon > end > > class Square < Rectangle >   include RegularPolygon >   def initialize >      super() >      check_sides_are_equal_length #defined in RegularPolygon > end > > -Michael Libby Yes. Modules offer all sorts of exciting possibilities if behavior can be coded generically enough with the subclasses providing key operations that enable the mixin. It's one aspect of Ruby that I'm learning to love. Definitely superior to interfaces, as say in Java. E.g. the relationship of Sets and Enumerable is one example. I didn't mean to be pedantic in the prior post. It's just I was confronted recently with a complicated hierarchy where someone used all sorts of principles to derive the hierarchy except the right one. We were in Java and so the above came out in single-inheritance style. Your module comment is well-received.