How do I create a subclass

Tim Olson tim at jumpnet.com
Tue Feb 10 13:58:52 UTC 1998


>I've successfully created my own classes in Squeak, but how do I
>create subclasses underneath them?

When you made your own classes, you likely edited the class template to 
make your new class a subclass of Object.  To subclass another class, 
simply put its name to the left of the subclass: selector, e.g.

Object subclass: MyClass
     instanceVariableNames: 'a1 a2'
     classVariableNames: ''
     poolDictionaries: ''
     category: 'NewClassesIveAdded'


MyClass subclass: MyDerivedClass
     instanceVariableNames: 'b1'
     .
     .


While this creates a proper class hierarchy, the standard browser is 
designed to show all the classes in a 2-level form of Category/Class, 
where associated classes are collected under a common category and 
displayed together.  You can view the actual hierarchy by selecting a 
class and choosing "hierarchy" from the menu of the class pane.




     -- tim





More information about the Squeak-dev mailing list