Handle Compatible Classes - MATLAB & Simulink (original) (raw)

Main Content

Basic Knowledge

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

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.

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 none of them are handle classes. However, there are situations in which a class provides some utility that is used by both handle and nonhandle subclasses. Because it is not legal to combine handle and nonhandle classes, the author of the utility class must implement two distinct versions of the utility.

The solution is to use handle-compatible classes. You can use handle-compatible classes with handle classes when forming sets of superclasses. Designate a class as handle compatible by using the HandleCompatible class attribute.

classdef (HandleCompatible) MyClass ... end

Handle Compatibility Rules

Handle-compatible classes (that is, classes whose HandleCompatible attribute is set to true) follow these rules:

A class that does not explicitly set its HandleCompatible attribute to true is:

Identify Handle Objects

To determine if an object is a handle object, use the isa function:

See Also

Topics