필터 지우기
필터 지우기

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개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by