MATLAB Object-Oriented Programming

(Joyce) #1

  • Type — Cash 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).


Methods


The Cash class defines these methods:



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

  • getCurrentValue — This method is the Cash class implementation of the abstract
    method defined by the Assets class. It returns the current value of this asset.

  • save — This method adds the specified amount of cash to the existing amount and
    returns a new Cash object with the current amount.

  • spend — This method deducts the specified amount from the current amount and
    returns a new Cash object with the current amount.


Cash Class Code


classdef Cash < financial.Assets
properties
Amount double = 0
end
properties (SetAccess = private)
Type = "Cash"
end
methods
function c = Cash(description,amount)
if nargin == 0
description = '';
amount = 0;
end
c.Description = description;
c.Amount = amount;
end
function value = getCurrentValue(c)
value = c.Amount;
end
function c = save(c,amount)
newValue = c.Amount + amount;
c.Amount = newValue;
end
function c = spend(c,amount)


A Class Hierarchy for Heterogeneous Arrays
Free download pdf