From: Gavin Sinclair Date: 2003-02-12T01:59:09+09:00 Subject: Re: inheriting from base classes On Wednesday, February 12, 2003, 3:48:09 AM, Chad wrote: > So, I see where David's coming from here. There are rules of thumb on > OO design, but the Ruby environment places higher value on > "responds-to?" than "is-a?" ...at least in my interpretation of it. > That having been said, these days I find myself (in Ruby, at least) > almost never inheriting from anything. Again, I'm not dogmatically > saying that you *shouldn't* use inheritance. I just tend to do what a) > feels right, b) gets the job done, and c) others can read (if that's > even necessary). In the last substantial project I did, using Ruby, I used inheritance, and realised after a while that it was not even technically necessary. I could have implemented it without inheritance, taking advantage of the "responds_to?" over "is_a?" value system. But sometimes it just makes sense. The beauty of Ruby is that we don't have to rely on inheritance in order to achieve certain things (i.e. we can add methods to existing classes, we can send messages to any object). But inheritance still has value as a means of structuring the system. I actually try to avoid using inheritance until I am certain that it is justified, in terms of representing structure, and not just (re)using an implementation. This works well for me as a design/refactoring compass. Gavin