Parent/child construction to have the possibility to retrieve info from the superclass object in the subclass object
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Sparse Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!