Path: utzoo!attcan!uunet!husc6!mailrus!cornell!rochester!rocksanne!entire!elt From: elt@entire.UUCP (Edward L. Taychert) Newsgroups: comp.lang.smalltalk Subject: Re: Specify New Classes in Smalltalk/V Summary: if you don't understand the issues, use subclass if you do, pick the correct one. Message-ID: <3273@entire.UUCP> Date: 21 Nov 88 19:03:21 GMT References: <1361@aucs.UUCP> <3269@entire.UUCP> <1766@imagine.PAWL.RPI.EDU> Distribution: na Organization: Entire Inc, East Rochester, NY Lines: 55 >In article <1361@aucs.UUCP>, 831059l@aucs.UUCP (Langlois) writes: >> In article <3269@entire.UUCP> elt@entire.UUCP (Edward L. Taychert) writes: >> ... >> use variableSubclass, this means that object instance variable can reference >> any kind of object. > > This is not, in general, good advice. For most classes, you should choose > just plain subclass. This means that the instance variables of the instances > of the class will all have names. These named instance variables can each > reference any kind of object. > > Use the variable* forms only for things like arrays which are going to > maintain a list of members. Even then, consider whether it wouldn't be > better to have, say, an instance variable which always contains an array > instead of indexed instance variables. In general, I think this is true. If your object will never be referred to like an array, "subclass" is correct. I recommended "variableSubclass" because it is the most general type of class. Using "variableSubclass" means that the object will respond to "new:", "at:" and "at:put:". Using "subclass", it will not. However, as Langlois points out, you may implement these methods yourself within the class. Doing so, however, adds a level of indirection which will slow you down `a little bit'. According to Digitalk customer support, there is no penalty in speed or memory for using "variableSubclass", even if you don't use its indexing capabilities. There is a potential risk, however, for using it blindly: If you implement a variable subclass of a object which is not variable and the super class implements (let's say) at:, the superclass's at: will not be inherited. I'm told that V286 changed class OrderedCollection from "variableSubclass" to "subclass". Creating a variable subclass of V286's OrderedCollection would probably be an error. If you use "variableSubclass", the object may contain named instance variables (pointers) of any object type and its `built in' array may contain objects of any type also. If you use "variableWordSubclass" or "variableByteSubclass:" the object cannot contain named instance variables and the array elements cannot refer to general objects, only words or bytes. Methods other than at: and at:put: will contain lines like "self at: 7" to operate on its contents. -- ____________________________________________________________________________ Ed Taychert Phone: USA (716) 381-7500 Entire Inc. UUCP: rochester!rocksanne!entire!elt 445 E. Commercial Street East Rochester, N.Y. 14445 _____________________________________________________________________________