Pattern: New Class
Context
In Smalltalk everything is an object, and all objects are
instances of a class. Programming an Application
in Smalltalk begins with the creation of one or more new classes.
Having identified a taxonomy of classes, one needs to be able to
define them in Dolphin.
Solution
- Consider the attributes and behaviour that the class will
implement.
- Choose a Class Name name for
the class.
- Decide where, in the existing class hierarchy, to
position the new class. This may involve choosing between
class inheritance
and object composition. You may also wish to decide
at this stage whether the class will be an Abstract Class or will be
subclassed from one. The best default choice is to
subclass Object which would provide a minimum
set of inherited behaviour suitable for virtually all
objects.
- Choose a set of Instance
Variable Names to represent the state of the object.
- Use a Class Hierarchy Browser to create the class.
- Open a Class Hierarchy Browser by choosing Tools/Class
Hierarchy Browser from any development tool
window.
- Select the class which the new class will
subclass from.
- Choose Class/New and enter the name of
the new class.
- In the source pane displaying the new class'
definition, add to the instance variable and
class variable lists as required to define the
state of the objects instances.
- Save the definition using Workspace/Accept..
- If any class
instance variables are required (rarely),
switch to the Class tab and in the code pane,
modify the instance variable list of the class,
and once again use Workspace/Accept to
save down the definition.
- Add a method or methods to perform any required Class Initialization
for the new class.
- Add appropriate Instance
Creation methods.
- Implement an Instance
Initialization method if required
- Add appropriate Accessor
Methods.
- Implement the behaviour of the class
Related Patterns