A Guide to MATLAB Object-Oriented Programming

With the introduction of cStar and cDiamond, the same class no longer represents both stars and diamonds. Even though both are derived from cShape and even though neither adds new features, cStar and cDiamond objects are different. These differences cast a big shadow on design because they force difficult choices between inheritance and vectorization. Here we discuss the differences and add some implementation details to our classes.
One of the nice things about inheritance, virtual functions, polymorphism, and arrays of objects is the promise that MATLAB will always find and execute the right function based on the object s type. Following this to its conclusion, you might get the idea that a cShape array should be able to hold objects in any combination of cShape, cStar, and cDiamond. In reality, the vectorized implementation inside cShape s group of eight cannot deal with a mixture of types. Vectorized operations rely on every object having exactly the same private structure, and exactly the same type. Therefore, even though cStar objects can masquerade as cShape objects, with respect to building object arrays, there is definitely a difference.
Unfortunately, MATLAB currently permits some questionable syntax. For example, using the code from Chapter 12, the commands in Code Listing 74 execute without causing an immediate error. The command in line 1 concatenates objects of different types. Line 2 is a variation on line 1. To make...