MATLAB Object-Oriented Programming

(Joyce) #1

Number: 7


b


b =


NumHandle with properties:


Number: 7


Modifying Handle Objects in Functions


When you pass a handle object to a function, MATLAB creates a copy of the handle in the
function workspace. Because copies of handles reference the same underlying object,
functions that modify the handle object effectively modify the object in the caller’s
workspace as well. Therefore, it is not necessary for functions that modify handle objects
passed as input arguments to return the modified object to the caller.


For more information, see “Object Modification” on page 5-63.


Deleting Handles


You can destroy handle objects by explicitly calling the handle delete method. Deleting
the handle of a handle class object makes all handles invalid. For example:


a = NumHandle;
b = a;
delete(a)
b.Number


Invalid or deleted object.


Calling delete on a handle object invokes the destructor function or functions for that
object. See “Handle Class Destructor” on page 7-16 for more information.


Initialize Properties to Contain Handle Objects


For information on the differences between initializing properties to default values in the
properties block and initializing properties from within the constructor, see “Initialize
Property Values” on page 8-18 and “Initialize Arrays of Handle Objects” on page 10-11.


Comparison of Handle and Value Classes
Free download pdf