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

GNU Smalltalk User's Guide

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

4.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
       instanceVariableNames: 'checknum checksleft'
       classVariableNames: ''
       poolDictionaries: ''
       category: nil !

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.
   !Checking methodsFor: '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.

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