In chapter , we showed how to represent the account of John Smith as an object. We will of course, also need to represent the accounts of Liza Jones and Mary Pole. To do this we may of course define account objects similar to account_1010
of John Smith for these accounts. The account of Liza Jones may be e.g. defined as follows:
account_1022: obj
owner: val "Liza Jones"
balance: var float
interestRate: var float
addInterest:
balance := balance + (balance * interestRate) / 100
deposit(amount: var float):
balance := balance + amount
withdraw(amount: var float) -> newB: var float:
balance:= balance - amount
newB := balance
The description of Liza Jones account is identical to the description of John Smiths account except for the value of owner
.
In general, the program should reflect that the accounts of Liza Jones and John Smith are of the same kind/form – it should appear from their descriptions that they both represents accounts. In addition, we should avoid repeating the same code at different places. In the next section, we show how to do that using the class mechanism.