From: "Mauricio Fernández" Date: 2003-02-11T23:45:27+09:00 Subject: Re: inheriting from base classes On Tue, Feb 11, 2003 at 11:40:14AM +0900, dblack@candle.superlink.net wrote: > Hi -- > > Gavin Sinclair and I have been involved in an interesting exchange > about the merits (or lack thereof) of inheriting from base classes, in > particular String/Array/Hash. This is also something that some of us > were chatting about at the conference in November. > > We're both very interested in hearing what people's views are on this. > Do you ever subclass String, Array, and Hash? Do you specifically > avoid doing so? I think Ruby貼s design favors aggregation over inheritance heavily. [I understand matz does too :)] There貼s a number of things against inheritance, in general: * you _have_ to know things about the implementation of superclasses since instance variables are not class-local * the probability of name clashes is too high if you add in modules and stuff * delegation is so convenient in Ruby you tend to forget about inheritance, since subclassing is a very serious decision you cannot take lightly * in general (although a little less pertinent to Ruby) designs based on object relationships (such as aggregation) are more flexible than those based on class relationships (more static, esp. in statically typed languages) Moreover, the examples you gave really don貼t seem at all to satisfy the 貼is-a貼 rule of thumb. I貼d definitely go with aggregation there. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com MS-DOS, you can't live with it, you can live without it. -- from Lars Wirzenius' .sig