From: niklas wernersson on 19 Jan 2010 13:07 I’m writing a program where a have a class representing a system, classdef classSystem properties dataSystem end % methods end The system contains two subsystems, classdef classSubSystemA properties dataA end methods function funcA() % do something involving dataA and dataSystem end end end classdef classSubSystemB properties dataB end methods function funcB() % do some involving dataB and dataSystem end end end I would like classSystem to contain both classSubSystemA and classSubSystemB. At the same time classSubSystemA and classSubSystemB need to access dataSystem. How do I do this? (I first tried to use inheritance but then ended up with two systems, classSubSystemA and classSubSystemB, and that is not the way I would like it to be. May it can be done in an other way?) Greatful for any suggestions on how to organize this. Best regards, Niklas
From: Matt J on 19 Jan 2010 14:04 "niklas wernersson" <niklas.wernersson(a)gmail.com> wrote in message <hj4sc8$eil$1(a)fred.mathworks.com>... > I’m writing a program where a have a class representing a system, > > classdef classSystem > properties > dataSystem > end > % methods > end ============== Why not make the 2 subsystems properties of classSystem classdef classSystem properties dataSystem SubSysA; %of type classSubSystemA SubSysB; %of type classSubSystemB end % methods end For SubsSysA/B to access dataSystem you could just pass dataSystem to methods of classSubSystemA/B as required. Alternatively, you could make dataSystem a handle object and pass this handle to the constructors of classSubSystemA/B when SubsSysA/B are created.
From: niklas wernersson on 20 Jan 2010 02:35 Thanks, I'll try this. Niklas "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hj4vn6$hpa$1(a)fred.mathworks.com>... > "niklas wernersson" <niklas.wernersson(a)gmail.com> wrote in message <hj4sc8$eil$1(a)fred.mathworks.com>... > > I’m writing a program where a have a class representing a system, > > > > classdef classSystem > > properties > > dataSystem > > end > > % methods > > end > ============== > > Why not make the 2 subsystems properties of classSystem > > classdef classSystem > properties > dataSystem > SubSysA; %of type classSubSystemA > SubSysB; %of type classSubSystemB > end > % methods > end > > For SubsSysA/B to access dataSystem you could just pass dataSystem to methods of classSubSystemA/B as required. > > Alternatively, you could make dataSystem a handle object and pass this handle to the constructors of classSubSystemA/B when SubsSysA/B are created.
|
Pages: 1 Prev: How to change the cursor and axis precision in a plot ? Next: generate fourier coefficients |