Jump to content
Sign in to follow this  
Christian Kjeld

Acces parent reference data in child

Recommended Posts

Is it possible to acces parent reference data in child class?

 

I am trying to implement somthing that looks like this:

 

NI-845x.pdf

post-288-0-19665500-1359218739.png

 

 

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:

 

  1. 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.
  2. make LV2 global to holde the reference, but agin it should not be the way
  3. 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

 

 

 

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 by twols

Share this post


Link to post
Share on other sites

If you have child classes you can use a class property node to access data inside the parent object (not the owner object).

 

Ton

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.