MATLAB Object-Oriented Programming

(Joyce) #1

Using BankAccount Objects


The BankAccount class, while overly simple, demonstrates how MATLAB classes behave.
For example, create a BankAccount object with an account number and an initial deposit
of $500:


BA = BankAccount(1234567,500)


BA =


BankAccount with properties:


AccountNumber: 1234567
AccountBalance: 500
AccountListener: [1x1 event.listener]


Use the getStatement method to check the status:


getStatement(BA)




Account: 1234567
CurrentBalance: 500.00
Account Status: open


Make a withdrawal of $600, which results in a negative account balance:


withdraw(BA,600)
getStatement(BA)




Account: 1234567
CurrentBalance: -100.00
Account Status: overdrawn


The $600 withdrawal triggered the InsufficientsFunds event. The current criteria
defined by the AccountManager class results in a status of overdrawn.


Make another withdrawal of $200:


withdraw(BA,200)
getStatement(BA)


Developing Classes — Typical Workflow
Free download pdf