Next: , Previous: , Up: Creating subclasses  


6.5.2 The Checking class

Our second subclass of Account represents a checking account. We will keep track of two facets:

We will define this as another subclass of Account:

Account subclass: Checking [
    | checknum checksleft |

We have two instance variables, but we really only need to initialize one of them—if there are no checks left, the current check number can’t matter. Remember, our parent class Account will send us the init message. We don’t need our own class-specific new function, since our parent’s will provide everything we need.

    init [
       <category: 'initialization'>
       checksleft := 0.
       ^super init
   ]

As in Savings, we inherit most of abilities from our superclass, Account. For initialization, we leave checknum alone, but set the number of checks in our checkbook to zero. We finish by letting our parent class do its own initialization.