newValue = c.Amount - amount;
if newValue < 0
c.Amount = 0;
disp('Your balance is $0.00')
else
c.Amount = newValue;
end
end
end
end
Default Object
The design of this class hierarchy uses an abstract root class (Assets). Therefore, the
Assets class must specify a concrete class to use as a default object by overriding
getDefaultScalarElement. In this case, options include:
- Use one of the existing concrete classes for the default object.
- Define a concrete class in the hierarchy to use for the default object.
This implementation adds the DefaultAsset class to the hierarchy as a subclass of the
Assets class. MATLAB creates objects of this class when:
- Creating arrays using indexed assignment with gaps in index numbers
- Loading heterogeneous arrays from MAT-files when MATLAB cannot find the class of
an array element.
This diagram shows the addition of the DefaultAsset class:
20 Designing Related Classes