MATLAB Object-Oriented Programming

(Joyce) #1
All
Numbers

Integers

Positive
Integers

Positives

Reals

The “is a” relationship is a good way to determine if it is appropriate to define a particular
subset in terms of existing supersets. For example, each of the following statements
makes senses:



  • A Positive Integer is an Integer

  • A Positive Integer is a Positive number


If the “is a” relationship holds, then it is likely you can define a new class from a class or
classes that represent some more general case.


Reusing Solutions


Classes are usually organized into taxonomies to foster code reuse. For example, if you
define a class to implement an interface to the serial port of a computer, it would probably
be similar to a class designed to implement an interface to the parallel port. To reuse
code, you could define a superclass that contains everything that is common to the two
types of ports, and then derive subclasses from the superclass in which you implement
only what is unique to each specific port. Then the subclasses would inherit all the
common functionality from the superclass.


Role of Classes in MATLAB
Free download pdf