MATLAB Object-Oriented Programming

(Joyce) #1

that are designed to listen for these notices. In this example, a simplified version of an
account manager program performs this task.


In this example, an account manager program determines the status of all bank accounts.
This program monitors the account balance and assigns one of three values:



  • open — Account balance is a positive value

  • overdrawn — Account balance is overdrawn, but by $200 or less.

  • closed — Account balance is overdrawn by more than $200.


These features define the requirements of the BankAccount and AccountManager
classes. Include only what functionality is required to meet your specific objectives.
Support special types of accounts by subclassing BankAccount and adding more specific
features to the subclasses. Extend the AccountManager as required to support new
account types.


Specifying Class Components


Classes store data in properties, implement operations with methods, and support
notifications with events and listeners. Here is how the BankAccount and
AccountManager classes define these components.


Class Data


The class defines these properties to store the account number, account balance, and the
account status:



  • AccountNumber — A property to store the number identifying the specific account.
    MATLAB assigns a value to this property when you create an instance of the class.
    Only BankAccount class methods can set this property. The SetAccess attribute is
    private.

  • AccountBalance — A property to store the current balance of the account. The class
    operation of depositing and withdrawing money assigns values to this property. Only
    BankAccount class methods can set this property. The SetAccess attribute is
    private.

  • AccountStatus — The BankAccount class defines a default value for this property.
    The AccountManager class methods change this value whenever the value of the
    AccountBalance falls below 0. The Access attribute specifies that only the
    AccountManager and BankAccount classes have access to this property.


Developing Classes — Typical Workflow
Free download pdf