MATLAB Object-Oriented Programming

(Joyce) #1

function defaultObject = getDefaultScalarElement
defaultObject = financial.DefaultAsset;
end
end
methods (Sealed)
% Implemented in separate files
% +financial.@Assets/pie.m
% +financial.@Assets/makeReport.m
pie(assetArray)
makeReport(assetArray)
end
end


For code listings for pie and makeReport, see “Operating on an Assets Array” on page
20-14.


Stocks Class


The Stocks class represents a specific type of financial asset. It is a concrete class that
implements the abstract members defined by the Assets class, and defines class
properties and methods specific to this type of asset.


Properties


The Stocks class defines these properties:



  • NumShares — The number of shares held for this asset.

  • Symbol — The ticker symbol corresponding to this stock.

  • Type — Stocks class implementation of the abstract property defined by the Assets
    class. This concrete property must use the same attributes as the abstract version
    (that is, SetAccess private).

  • SharePrice — Dependent property for the price per share. The get.SharePrice
    method obtains the current share price from web services when this property is
    queried.


Methods


The Stocks class defines these methods:



  • Stocks — The constructor assigns property values and supports a default constructor
    called with no input arguments.


A Class Hierarchy for Heterogeneous Arrays
Free download pdf