Parent/child construction to have the possibility to retrieve info from the superclass object in the subclass object
11 views (last 30 days)
Show older comments
Dear all,
Suppose an object MainObj has been declared that has two variables of which one is also an object "SubObj"
if I would call a function of SubObj, "DoSomething", how could I retrieve the upper-level MainObj?
Maybe the Parent/Child contruction would work but how should I construct my objects/classes?
many thanks!
Kees
%% separate file with MainObj
classdef MainObj < handle
properties (SetObservable)
variable1 = [];
variable2 = [];
end
methods
function obj = MainObj()
obj.variable1 = SubObj();
end
end
end
%% separate file with SubObj
classdef SubObj < handle
properties (SetObservable)
subvariable = [];
end;
methods
function DoSomething(obj)
obj.subvariable = 10;
% How could I retrieve the Parent object of "obj"
% for example, something like this:
ParentObject = get(obj, 'Parent');
ParentObject.variable2 = 1;
end;
end;
end
0 Comments
Answers (0)
See Also
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!