From: ahoward Date: 2002-11-11T06:44:55+09:00 Subject: Re: return MyClass.new vs self.type.send :new On Mon, 11 Nov 2002 dblack@candle.superlink.net wrote: [snip] > Doesn't that give you what you need, and wouldn't it scale better? [snip] not at all, i'll give you an example : i've used the 'splitting a classes's methods out into a module but also having a concrete class' technique to create a pair called module HTML::TableMethods ... end clase HTML::Table < Array include HTML::TableMethods ... end you can imagine what they do... this allows me to do a database query, say tuples = pgconn.query sql where tuples is an Array of Array of String - which in fact is how the postgresql lib works. tuples might be *very* large. if tuples.size something like 30,000 rows then i would need to instatiate an HTML::Table and then instatiate 30,000 more objects to populate the table - slow. so i thought to myself, this is a perfect job for a module which can then be used to extend an object on the fly. after i created all the module methods i realized they work fine in a concreate class too... you get the picture the end result is that one can 'cast' an object to another type on the fly - which can be appropriate in some circumstances. anyhow, i was just showing that you can design things so a class can be cast to another with some effort, whether the other class is a relative or not. you can't do that with the normal inheritence you've shown. is it actually usefull to be able to refer to child object as the type of it's parent. this idiom is used all the time in c++ where simply pointing an appropriately typed pointer at an object you may access it's method as parent, child, grandchild, etc. does this make sense? -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================