MATLAB Object-Oriented Programming

(Joyce) #1

  • ReadOnlyProps – class with two read-only properties. The class constructor assigns a
    handle object of type HanClass to the PropHandle property and a value object of
    type ValClass to the PropValue property.

  • HanClass – handle class with public property

  • ValClass – value class with public property


classdef ReadOnlyProps
properties(SetAccess = private)
PropHandle
PropValue
end
methods
function obj = ReadOnlyProps
obj.PropHandle = HanClass;
obj.PropValue = ValClass;
end
end
end


classdef HanClass < handle
properties
Hprop
end
end


classdef ValClass
properties
Vprop
end
end


Create an instance of the ReadOnlyProps class:


a = ReadOnlyProps


a =


ReadOnlyProps with properties:


PropHandle: [1x1 HanClass]
PropValue: [1x1 ValClass]


Use the private PropHandle property to set the property of the HanClass object it
contains:


Properties Containing Objects
Free download pdf