- AccountListener — Storage for the InsufficentFunds event listener. Saving a
BankAccount object does not save this property because you must recreate the
listener when loading the object.
Class Operations
These methods implement the operations defined in the class formulation:
- BankAccount — Accepts an account number and an initial balance to create an object
that represents an account. - deposit — Updates the AccountBalance property when a deposit transaction
occurs - withdraw — Updates the AccountBalance property when a withdrawal transaction
occurs - getStatement — Displays information about the account
- loadobj — Recreates the account manager listener when you load the object from a
MAT-file.
Class Events
The account manager program changes the status of bank accounts that have negative
balances. To implement this action, the BankAccount class triggers an event when a
withdrawal results in a negative balance. Therefore, the triggering of the
InsufficientsFunds event occurs from within the withdraw method.
To define an event, specify a name within an events block. Trigger the event by a call to
the notify handle class method. Because InsufficientsFunds is not a predefined
event, you can name it with any char vector and trigger it with any action.
BankAccount Class Implementation
It is important to ensure that there is only one set of data associated with any object of a
BankAccount class. You would not want independent copies of the object that could
have, for example, different values for the account balance. Therefore, implement the
BankAccount class as a handle class. All copies of a given handle object refer to the
same data.
3 MATLAB Classes Overview