A Guide to MATLAB Object-Oriented Programming

There is another common form of inheritance, very different from parent child inheritance, called composition. [*] Using an object in composition is easy. All you have to do is assign an object as the value for a private member variable. For example, if double represents a class, we could say that this.mSize is one element of the composition. This means that even simple classes use a composition of built-in types. Complex classes add structures and objects to the composition. Unlike parent child inheritance where the parent s interface is public, the interface of every object in the composition remains private.
In composition, there are always two objects involved. We need to define some terminology so we can keep these two objects straight. The first object is composed from a collection of private member variables of various types. Let s call this object the primary object. In our example code, cShape, cStar, and cDiamond are all primary objects. Every private member variable held by the primary object can be an object. Let s call these objects secondary objects. In our example code, mSize and mPoints represent two secondary objects.
In MATLAB, there is overlap between parent child inheritance and composition. Parent child inheritance is a special case of composition. The child is a primary object and the parent is a secondary object. This might seem backward but it is consistent with the way primary and secondary were defined. The parent is a secondary object because the parent object is...