handle
Abstract base class for objects that are shared by reference.
Category: Other public functions: lang
Syntax
classdef MyClass < handle
Declares a class whose objects are handle objects.
isa(obj, 'handle')
Tests whether an object is a handle object.
Description
Objects of ordinary (value) classes are copied on assignment: changing the copy leaves the original alone. Objects of a class that inherits from handle are references: the assignment b = a makes both variables point to the same object, so a change through either is seen through both. This suits things that have an identity, such as a window, a connection or a shared cache.
handle objects also provide delete, isvalid and events. containers.Map and memoize objects are examples of handle objects that need no class definition.
Example
Reference behavior
a = containers.Map();
b = a;
b('k') = 5;
disp(a.isKey('k'))
disp(isa(a, 'handle'))
1
1
Notes
Called as a function with no argument, handle raises an error in MatLivre; it is used only as a superclass and with isa.