From: dblack@... Date: 2003-02-12T02:05:43+09:00 Subject: Re: inheriting from base classes Hi -- On Wed, 12 Feb 2003, Gavin Sinclair wrote: > That's what you should be aiming for in OO code: users don't have to > do any low-level stuff on your objects. You implement just the > methods they need. They shouldn't have to know that Array is used to > implement it. They don't; If they're just require'ing a library, and using the published/documented interface, that's all they need to know. > Of course, you need a way of building up a roster. That might be by > parsing a text file, or you may need to resort to: > > class ClassRoster > def <<(o) > @roster = [] > end > end > > Rather than say "gosh, what a pain doing such a boring method", look > for ways to eliminate the need for it. class ClassRoster < Array # :-) > Or, if a few such methods are > indeed perfectly justifiable, then use one of Ruby's forwarding > mechanisms, or try to do more than just delegate (error checking, for > instance). > > At the end of the day, the fewer methods per class, the better. > Superfluous methods cloud the intention of the class. (String et al > are excluded from this rule for obvious reasons.) This comes back to the original question -- why? Especially in a language where runtime objects may or may not correspond to the capabilities of their (historical) class. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav