MATLAB Object-Oriented Programming

(Joyce) #1

pd


pd =



















PropertyDefaults with properties:
p1: ' 4:45 PM'
p2: 'green'
p3: 0.7854

Call the resetDefaults method, which is inherited from the Utility class. Because
the PropertyDefaults class is not a handle class, return the modified object.


pd = pd.resetDefaults


pd =


PropertyDefaults with properties:


p1: ' 4:54 PM'
p2: 'red'
p3: 1.5708


If the PropertyDefaults class was a handle class, then you would not need to save the
object returned by the resetDefaults method. To design a handle compatible class like
Utility, ensure that all methods work with both kinds of classes.


Subclassing Handle-Compatible Classes


According to the rules described in “Handle Compatibility Rules” on page 12-40, when
you combine a handle superclass with a handle-compatible superclass, the result is a
handle subclass, which is handle compatible.


However, subclassing a handle-compatible class does not necessarily result in the
subclass being handle compatible. Consider the following two cases, which demonstrate
two possible results.


Combine Nonhandle Utility Class with Handle Classes


Suppose that you define a class that subclasses a handle class, and the handle compatible
Utility class discussed in “A Handle Compatible Class” on page 12-41. The
HPropertyDefaults class has these characteristics:


How to Define Handle-Compatible Classes
Free download pdf