Superclass of all handle classes
handle class is the superclass for all classes that follow
handle semantics. A handle is a variable that refers to an object of a handle class.
Multiple variables can refer to the same object.
handle class is an abstract class, so you cannot create an
instance of this class directly. You use the
handle class to derive
other classes, which can be concrete classes whose instances are handle objects.
To define a handle class, derive your class from
handle using the
syntax in the following
classdef MyHandleClass < handle ... end
Deriving from the
handle class enables your subclass
Inherit several useful methods (Handle Class Methods)
Define events and listeners (Events and Listeners Syntax)
Define dynamic properties (Dynamic Properties — Adding Properties to an Instance)
Implement set and get methods (Implement Set/Get Interface for Properties)
Customize copy behavior (Implement Copy for Handle Classes)
For information about using handle classes, see Handle Classes
For information on class attributes, see Class Attributes.
|Create event listener bound to event source|
|Create event listener without binding to event source|
|Notify listeners that event is occurring|
|Find handle objects|
|Find meta.property object|
|Delete handle object|
|Determine valid handles|
|Determine equality or sort handle objects|
|Create empty array|
MySubclass class derives from the
handle class. The property set method does not return the
object passed to the method, as is required by a value class:
classdef MySubclass < handle properties Client tcpclient end methods function set.Client(obj,c) if isa(c,'tcpclient') obj.Client = c; end end end end
Create an object of
MySubclass and assign a
tcpclient object to the
t = MySubclass; t.Client = tcpclient('www.mathworks.com', 80);
Copying a handle object does not copy the underlying data associated with the object. The copy is another handle referring to the same object. Therefore, if a function modifies a handle object passed as an input argument, the modification affects the original input object in the caller's workspace.
In contrast, nonhandle objects (that is, value objects) associate data with a particular variable. Functions must return modified value objects to change the object outside of the function's workspace.
For information on passing objects to functions, see Object Modification and
MATLAB® destroys handle objects when there are no references to the object.
You can explicitly remove a handle object by calling its
delete method. The
handle class enables you to control what happens when handle
objects are destroyed, either implicitly when no references exist or explicitly when
you delete the object.
For more information, see Handle Class Destructor.
Any code can respond to the pending deletion of a handle object by defining a
listener for that object’s
MATLAB triggers this event before calling the object’s
For more information on using events and listeners, see Events and Listeners Syntax.