Value Object Properties
The copy behavior of values stored as properties in value objects is the same as numeric variables.
For example, suppose vobj1 is a value object with property a:
vobj1.a = 8;
If you copy vobj1 to vobj2, and then change the value of vobj1 property a, the value of the copied
object's property, vobj2.a, is unaffected:
vobj2 =vobj1;
vobj1.a = 5;
vobj2.a
ans =
8
Handle Object Copy Behavior
Here is a handle class called HdClass that defines a property called Data.
classdef HdClass < handle
properties
Data
end
methods
function obj = HdClass(val)
if nargin > 0
obj.Data = val;
end
end
end
end
Create an object of this class:
hobj1 = HdClass(8)
Because this statement is not terminated with a semicolon, MATLAB displays information about the
object:
hobj1 =
HdClass with properties:
Data: 8
The variable hobj1 is a handle that references the object created. Copying hobj1 to hobj2 results in
another handle referring to the same object:
hobj2 = hobj1
hobj2 =
HdClass with properties:
Data: 8
Object Behavior
16-3
Précédent

- 597/1450

Suivant