www.delorie.com/gnu/docs/smalltalk/gst_58.html   search  
Buy GNU books!

GNU Smalltalk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.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: '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.

4.4.1 Creating a new class  
4.4.2 Documenting the class  So anybody will know what it's about
4.4.3 Defining a method for the class  So it will be useful
4.4.4 Defining an instance method  One of two kind of methods (the others, class methods, are above)
4.4.5 Looking at our Account  which will sorely show that something is still missing.
4.4.6 Moving money around  Let's make it more fun!
4.4.7 What's next?  Yeah, what's next?!?

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003