Next: , Previous: , Up: Tutorial  

6.4 Creating a new class of objects

With the basic techniques presented in the preceding chapters, we’re ready do our first real Smalltalk program. In this chapter we will construct three new types of objects (known as classes), using the Smalltalk technique of inheritance to tie the classes together, create new objects belonging to these classes (known as creating instances of the class), and send messages to these objects.

We’ll exercise all this by implementing a toy home-finance accounting system. We will keep track of our overall cash, and will have special handling for our checking and savings accounts. From this point on, we will be defining classes which will be used in future chapters. Since you will probably not be running this whole tutorial in one Smalltalk session, it would be nice to save off the state of Smalltalk and resume it without having to retype all the previous examples. To save the current state of GNU Smalltalk, type:

   ObjectMemory snapshot: ''

and from your shell, to later restart Smalltalk from this “snapshot”:

   $ gst -I

Such a snapshot currently takes a little more than a megabyte, and contains all variables, classes, and definitions you have added.

Next: , Previous: , Up: Tutorial