フィルターのクリア

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 Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by