Programming |
The Stock get Method
The get
method provides a way to access the data in the stock object using a "property name" style interface, similar to Handle Graphics. While in this example the property names are similar to the structure field name, they can be quite different. You could also choose to exclude certain fields from access via the get
method or return the data from the same field for a variety of property names, if such behavior suits your design.
function val = get(s,propName) % GET Get stock property from the specified object % and return the value. Property names are: NumberShares % SharePrice, Descriptor, Date, CurrentValue switch propName case 'NumberShares' val = s.numShares; case 'SharePrice' val = s.sharePrice; case 'Descriptor' val = get(s.asset,'Descriptor'); % call asset get method case 'Date' val = get(s.asset,'Date'); case 'CurrentValue' val = get(s.asset,'CurrentValue'); otherwise error([propName ,'Is not a valid stock property']) end
Note that the asset object is accessed via the stock object's asset field (s.asset
). MATLAB automatically creates this field when the class
function is called with the parent argument.
The Stock Constructor Method | The Stock set Method |
© 1994-2005 The MathWorks, Inc.