MATLAB: Get property of the parent object

MATLABmethodsobject oriented programmingoopproperties

If object contain an other object from another class, how can I access to the proprieties of that object from the child object ? In other words related to the example I give, how can I use the variable saved in Parent in the child ?
My parent class:
classdef Parent < handle
properties
name = '' ;
child = {};
end
methods
function obj = Parent(name)
obj.name = name
end
function createChild(obj, name)
obj.child = child(name)
end
end
end
My child class:
classdef child < handel
properties
name = '';
end
methods
function obj = child(name)
obj.name = name;
end
function createBlock(obj)
add_block('library/body', strcat(parent.name, '/', obj.name)
end
end
end

Best Answer

Perhaps, this is what you want to do:
classdef Parent < handle
properties (SetAccess = private)
name = '';
child = [];
end
methods
function this = Parent(name)
this.name = name;
end
function createchild(this, name)
this.child = child(name, this) %The child is now informed of his parent
end
end
classdef Child < handle
properties (SetAccess = private)
name = '';
parent = [];
end
methods (Access = ?Parent) %Only Parent is allowed to construct a child
function this = Child(name, parent)
this.name = name;
this.parent = parent;
end
end
methods
function createblock(this)
add_block('library/body', sprintf('%s/%s, parent.name, this.name));
end
end
end