Christian Kjeld Posted January 26, 2013 Report Share Posted January 26, 2013 Is it possible to acces parent reference data in child class? I am trying to implement somthing that looks like this: NI-845x.pdf The SPI class initialize's the SPI script reference that I then want to use in the childe class (S25FL016A). By doing it this way I only have to inplement the "RUN" and "Configuration" method it in the SPI class. And not in all the child classes under SPI. I have tried: to use a data member accesor but it is ugly code because I have to pass the reference from the parrent class in to the childe for making it work. make LV2 global to holde the reference, but agin it should not be the way use the "To More Specific Class" in the child class, but it only returns the reference without any data in it. I am programming it in LabVIEW 2011 Quote Link to comment
Ton Plomp Posted January 27, 2013 Report Share Posted January 27, 2013 I assume you have a by-reference design (for instance a DVR in a class), you should use a constant class S25FL016A as input for the NI-845X 'Initialize', in your SPI 'Initialize' you call the parent method. Now in the S25FL016A-method, you use a 'To More Generic' class with an SPI constant. However I am wondering if you design is correct. (I might misinterpreted your UML). But I read that S25FL016A overrides SPI which overrides NI-845X. Now I don't think that's a good design, the SPI is part of the NI-845X, not a more specific type. Your NI-845X should have a member of the SPI type, on the 'Intialize' method of SPI, you feed a reference to the owner (not parent) class. Now you have access to the owner of the SPI inside the SPI class, and you can have 'Community' methods in the NI-854X class that are accessible by the SPI class. Ton Quote Link to comment
twols Posted February 2, 2013 Report Share Posted February 2, 2013 (edited) I'm working on a similar problem too. I do have a generic driver and its specific implementations. The data is stored in a DVR, but I have to access and extend the variables in the child classes. I could use the Variant to store the data (accessing it by read and write attribute). I would access the data out of every child without passing the reference to them.. I'm going to test it on monday, but maybe somebody has a better solution. Edited February 2, 2013 by twols Quote Link to comment
Ton Plomp Posted February 2, 2013 Report Share Posted February 2, 2013 If you have child classes you can use a class property node to access data inside the parent object (not the owner object). Ton Quote Link to comment
K-node Posted February 2, 2013 Report Share Posted February 2, 2013 Ton, I think 2Ls wants the DVR to reference a different or rather extended collection of data that the parent object has. For 2Ls, it is important to remember that a DVR is a reference to specifically typed data. There is no way to make a DVR reference something that it isn't. So, the DVR does not really buy much here. A suggestion for 2Ls... Perhaps the private data in the parent can be an object itself, call it ObjectData.lvclass. Now when a child gets Initialized, it can call the parents 'Write ObjectData' accessor with a class derived from ObjectData.lvclass. This derived class has the extra information needed. If you still need to use a DVR, perhaps supply a 'New Data Value Reference' node with ObjectData.lvclass or one of it's derived classes. Now 'parent' methods can get access to the what the child implementation created. Is that what you were thinking 2Ls? Kurt 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.