Main Content

handle Class

Superclass of all handle classes

Description

The handle class is the superclass for all classes that follow handle semantics. A handle is an object that indirectly references its data. The handle class is abstract and cannot be directly instantiated.

To define a handle class, derive your class from handle by declaring it as a superclass in classdef.

classdef MyHandleClass < handle
    ...
end

Deriving from the handle class enables your subclass to:

For information about using handle classes, see Handle Classes

Class Attributes

Abstract
true
ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Methods

expand all

Events

Event NameTriggerEvent DataEvent Attributes
ObjectBeingDestroyedTriggered when the handle object is about to be destroyed, but before calling the delete method. event.EventData

NotifyAccess: private

ListenAccess: public

Examples

collapse all

The 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 Client property.

t = MySubclass;
t.Client = tcpclient('www.mathworks.com', 80);

More About

expand all

Extended Capabilities

expand all

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2008a