From: Robert Klemme Date: 2010-11-02T18:31:56+09:00 Subject: Re: the dark side of inherited methods On Tue, Nov 2, 2010 at 4:29 AM, Tony Arcieri wrote: > On Sun, Oct 31, 2010 at 5:49 PM, James Edward Gray II > wrote: > >> It is a problem with inheritance and another reason why inheritance is >> almost never what we want. > > That's a pretty extreme position to take. Inheritance is an indispensable > tool. That said, I will agree that "is a" relationships come up far less > frequently than 'has a" relationships. I believe this is what James wanted to stress: inheritance is used far too often for purposes where it's not appropriate. A real is_a relationship is pretty rare yet many people use inheritance, especially with core / std lib classes as parents which almost always is a code smell. Side note: there are languages such as Eiffel and C++ which have support for implementation inheritance (i.e. the interface changes incompatibly from super class to sub class) and in those languages inheritance can be used more often than in language which lack these features (e.g. Java). > I would say that it would make far more sense to create a Vector class which > "has a"(n) array, and make the Vector an Enumerable. Of course, what makes > even more sense is to use the Vector class provided by "require 'matrix'" Absolutely. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/