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 />

Multiple Inheritance<br />

In the multiple inheritance case, a class of objects inherits attributes from<br />

more than one base class. The derived class object gets fields from all the base<br />

classes, as well as fields of its own.<br />

Multiple inheritance can encompass more than one generation. For example,<br />

each of the base class objects could have inherited fields from multiple<br />

base class objects, and so on. Multiple inheritance is implemented in the<br />

constructors by callingclass with more than three arguments.<br />

obj = class(structure,'classname',baseclass1,baseclass2,...)<br />

You can append as many base class arguments as desired to the class input<br />

list.<br />

Nonunique Method Names in Base Classes<br />

Multiple base classes can have associated methods of the same name. In this<br />

case, <strong>MATLAB</strong> calls the method associated with the base class that appears<br />

first in the class function call in the constructor function. There is no way to<br />

access subsequent base class functions of this name.<br />

Aggregation<br />

In addition to standard inheritance, <strong>MATLAB</strong> objects support containment or<br />

aggregation. That is, one object can contain (embed) another object as one of<br />

its fields. For example, a rational object might use two polynom objects, one<br />

for the numerator and one for the denominator.<br />

You can call a method for the contained object only from within a method<br />

for the outer object. When determining which version of a function to call,<br />

<strong>MATLAB</strong> considers only the outermost containing class of the objects passed<br />

as arguments; the classes of any contained objects are ignored.<br />

See “Example — The Portfolio Container” on page 9-58 for an example of<br />

aggregation.<br />

9-40

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

Saved successfully!

Ooh no, something went wrong!