MATLAB Object-Oriented Programming

(Joyce) #1

Handle Compatible Classes


In this section...
“Basic Knowledge” on page 12-39
“When to Use Handle Compatible Classes” on page 12-39
“Handle Compatibility Rules” on page 12-40
“Identify Handle Objects” on page 12-40

Basic Knowledge


The material presented in this section builds on knowledge of the following information.


  • “Design Subclass Constructors” on page 12-9

  • “Subclassing Multiple Classes” on page 12-22

  • “Comparison of Handle and Value Classes” on page 7-2


Key Concepts

Handle-compatible class — a class that you can include with handle classes in a class
hierarchy, even if the class is not a handle class.


  • All handle classes are handle-compatible.

  • All superclasses of handle-compatible classes must also be handle compatible.


HandleCompatible — the class attribute that defines nonhandle classes as handle
compatible.

When to Use Handle Compatible Classes


Typically, when deriving a MATLAB class from other classes, all the superclasses are
handle classes, or else none of them are handle classes. However, there are situations in
which a class provides some utility that is used by both handle and non-handle subclasses.
Because it is not legal to combine handle and non-handle classes, the author of the utility
class must implement two distinct versions of the utility.

The solution is to use handle-compatible classes. Handle compatible classes are a type of
class that you can use with handle classes when forming sets of superclasses. Designate a

Handle Compatible Classes
Free download pdf