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: 'myimage.im'
and from your shell, to later restart Smalltalk from this “snapshot”:
$ gst -I myimage.im
Such a snapshot currently takes a little more than a megabyte, and contains all variables, classes, and definitions you have added.
|• A new class:||Creating a new class|
|• Documenting the class:||So anybody will know what it’s about|
|• Defining methods:||So it will be useful|
|• Instance methods:||One of two kind of methods (the others, class methods, are above)|
|• A look at our object:||which will sorely show that something is still missing.|
|• Moving money around:||Let’s make it more fun!|
|• Next coming:||Yeah, what’s next?!?|