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

Main Content

Methods for Handle and Value Objects

Objects passed to methods of handle-compatible classes can be either handle or value objects. There are two different behaviors to consider when implementing methods for a class that operate on both handles and values:

Handle compatible methods generally do not alter input objects because the effects of such changes are not the same for handle and nonhandle objects.

See Object Modification for information about modifying handle and value objects.

Modify Value Objects in Methods

If a method operates on both handle and value objects, the method must return the modified object. For example, the setTime method returns the object it modifies:

classdef (HandleCompatible) Util % Utility class that adds a time stamp properties TimeStamp end methods function obj = setTime(obj) obj.TimeStamp = now; end end end

See Also

Topics