Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!argosy!kentb From: kentb@argosy.UUCP (Kent Beck) Newsgroups: comp.lang.smalltalk Subject: Re: To Subclass or Encapsulate? (WAS: Access Methods) Message-ID: <1254@argosy.UUCP> Date: 24 Apr 91 23:02:59 GMT References: <2815b936.c65@petunia.CalPoly.EDU> Sender: news@argosy.UUCP Reply-To: kentb@shark.UUCP (Kent Beck) Distribution: usa Organization: MasPar Computer Corp, Sunnyvale CA Lines: 28 Re: stupid questions. Pish and likewise tosh- these are good questions- witness the volume of wisdom they stimulate... Re: subclass vs. delegate. Two questions of varying weight depending on your programming style, 1) should the subclass respond to all the public protocol of the superclass and 2) where can I inherit the most implementation? In the case of Vector I would probably opt to make it a subclass of Number because I inherit so much, and depending on my masochism level on that particular day either have a "bytes" instance variable which would be bound to an Array or ByteArray, or make the class Vector a byte variable subclass. The later wouldn't work as well if vectors changed size dynamically. If you believe in inheritance as classification you accord more weight to 1) above, and you probably think that Dictionary as a subclass of Set is a travesty. If instead you use inheritance as a code sharing mechanism then 2) is more important and SystemDictionary as a subclass of Dictionary makes no sense. The Dictionary methods which are inherited are at:, at:put: and includesKey:. SystemDictionary adds a hundred or so new methods which might be better shared from some other class we haven't discovered yet because we've been staring at the current implementation so long. So the answer to your question is, of course, it depends. I generally opt for maximizing code sharing and I find that the classification dimension sorts itself out pretty well. This gives me the ability to organize inheritance hierarchies mechanically (by asking "which alternative shares the most code") without letting preconceptions interfere with the best use of the language's resources. Kent