Parent/child construction to have the possibility to retrieve info from the superclass object in the subclass object
조회 수: 11 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!