23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9 Classes and Objects<br />

Example — The Portfolio Container<br />

This example is divided into the following topics:<br />

• “Designing the Portfolio Class” on page 9-58<br />

• “The Portfolio Constructor Method” on page 9-59<br />

• “The Portfolio display Method” on page 9-60<br />

• “The Portfolio pie3 Method” on page 9-61<br />

• “Creating a Portfolio” on page 9-62<br />

Aggregation is the containment of one class by another class. The basic<br />

relationship is: each contained class “is a part of” the container class.<br />

For example, consider a financial portfolio class as a container for a set of<br />

assets (stocks, bonds, savings, etc.). Once the individual assets are grouped,<br />

they can be analyzed, and useful information can be returned. The contained<br />

objects are not accessible directly, but only via the portfolio class methods.<br />

See “Example — Assets and Asset Subclasses” on page 9-41 for information<br />

about the assets collected by this portfolio class.<br />

Designing the Portfolio Class<br />

The portfolio class is designed to contain the various assets owned by a given<br />

individual and provide information about the status of his or her investment<br />

portfolio. This example implements a somewhat over-simplified portfolio<br />

class that<br />

• Contains an individual’s assets<br />

• Displays information about the portfolio contents<br />

• Displays a 3-D pie chart showing the relative mix of asset types in the<br />

portfolio<br />

Required Portfolio Methods<br />

The portfolio class implements only three methods:<br />

9-58

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!