Advertisement
Guest User

Untitled

a guest
May 12th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Object subclass: #Account.
  2. Account instanceVariableNames: 'balance'.
  3.  
  4. Account class extend [
  5.        new [
  6.            | r |
  7.            <category: 'instance creation'>
  8.            r := super new.
  9.            r init.
  10.            ^r
  11.       ]
  12.    ]
  13.  
  14.   Account extend [
  15.         init [
  16.             <category: 'initialization'>
  17.             balance := 0
  18.         ]
  19.     ]
  20.  
  21.   Account extend [
  22.               spend: amount [
  23.                   <category: 'moving money'>
  24.                   balance := balance - amount
  25.               ]
  26.               deposit: amount [
  27.                   <category: 'moving money'>
  28.                   balance := balance + amount
  29.               ]
  30.           ]
  31.  
  32.   Account extend [
  33.        printOn: stream [
  34.            <category: 'printing'>
  35.            super printOn: stream.
  36.            stream nextPutAll: ' with balance: '.
  37.            balance printOn: stream.
  38.        ]
  39.    ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement