Programming Previous page   Next Page

The Asset Constructor Method

The asset class is based on a structure array with four fields:

This information is common to asset child objects (stock, bond, and savings), so it is handled from the parent object to avoid having to define the same fields in each child class. This is particularly helpful as the number of child classes increases.

The function uses a switch statement to accommodate three possible scenarios:

The asset constructor method is not intended to be called directly; it is called from the child constructors since its purpose is to provide storage for common data.


Previous page  Example -- Assets and Asset Subclasses The Asset get Method Next page

© 1994-2005 The MathWorks, Inc.