Next: , Previous: , Up: Creating classes  


6.4.6 Moving money around

We can now create accounts, and look at them. As it stands, though, our balance will always be 0—what a tragedy! Our final methods will let us deposit and spend money. They’re very simple:

   Account extend [
       spend: amount [
           <category: 'moving money'>
           balance := balance - amount
       ]
       deposit: amount [
           <category: 'moving money'>
           balance := balance + amount
       ]
   ]

With these methods you can now deposit and spend amounts of money. Try these operations:

   a deposit: 125
   a deposit: 20
   a spend: 10