Navigation:  Appendix B: Dolphin Pattern Book > Class Patterns >

New Class

Previous pageReturn to chapter overviewNext page


In Smalltalk everything is an object, and all objects are instances of a class. Programming an application in Smalltalk usually begins with the design of one or more new classes. Having identified a taxonomy of classes what are the steps required to translate them into Smalltalk.


1.Consider the attributes and behaviour that the class will implement and choose a Class Name for the new class.
2.Decide where, in the existing class hierarchy, to subclass the new class. This may involve choosing between Inheritance vs Composition. Often, a good default choice is to subclass from Object since you can always change the location in the class hierarchy at a later date.You may also wish to decide at this stage whether the class will be an Abstract Class or a Singleton.
3.Use a Class Browser and the Class/New command to create the class. Consider the possible Instance Variable Roles and then edit the definition to add instance variables to represent the state of the object. Also decide if any class variables or class instance variables are likely to be required and add these where necessary.
4.Add a New Method to perform any required Class Initialization for the new class. Remember to evaluate an expression in a workspace that will cause this initialization to be run for the first time.
5.Add appropriate class side Instance Creation Methods.
6.Implement an Instance Initialization method if required.
7.Add the necessary Accessor Methods that will allow access to the instance variables.
8.Implement the behaviour of the class with additional instance methods.

Related Patterns

Abstract Class, Abstract Factory, Class Name, Class Initialization, Singleton