LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP Inheritance Base Class Private Data

One thing that is not clear to me is why when I inherit from a base class why it is not part of the new class control.  How do I get at the private data for the base class?  I have two classes within one project, set the inheritance of one class to inherit from the other, but don’t see how to get at the private data from the base class.  Any ideas what is going wrong?  Also, to inherit from a class does the base class have to be in the same project?  I have one base class that I want to share with 3 other classes.

 Matt
Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 1 of 9
(7,092 Views)

Class data is private and can only be accessed using bundle/unbundle nodes inside class member VIs. Even if a class inherits from another class, it doesn't get direct access to the private data of its parent or grandparent. You have to create accessor VIs to read and write class data from outside the class itself. The child class can then call these accessor VIs.

 

Advantages of inheritance in light of this:

  • The child class "is a" parent class object, so you can call parent methods on the child class data.
  • The parent class can designate special member function VIs as Protected, meaning only it and its children can call the function. This still allows some special access to children that other classes or VIs outside class hierarchies can't use.
Jarrod S.
National Instruments
Message 2 of 9
(7,070 Views)

For reference it looks like I found the document that I have been looking for:

 

http://zone.ni.com/reference/en-XX/help/371361E-01/lvdialog/create_accessor_db/

 

It covers some of the advanced topics wiht LVOOP.

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 3 of 9
(7,042 Views)

I have a relativly simple class structure. AES-128 and plain are child classes of encryption. I can not seem to access the data in my child classes. Do I need to create static or dynamic data accessors? In this example I created static data accessor in the encryption class because I the data accessor in the child classes would be identical.

 

I am missing something fundamental in LVOOP please help.

 

classes.png

0 Kudos
Message 4 of 9
(6,496 Views)

You need to use an accessor to access parent data from within a child class VI. A child class does not have direct access to its parent's data, as explained above. A VI within a class can only directly access (through unbundle on the class wire) data that is defined at the same level of the hierarchy as the VI. A static accessor is fine, unless the child might need to override the parent accessor by providing some other data.

 

Does that help? If using an accessor doesn't solve your problem, can you attempt to describe the problem more clearly?

Message 5 of 9
(6,489 Views)

So then the static accessors in the parent class are valid to get data into the "class". But within each child method does there need to be a parent data accessor when parent data needs to be accessed?

 

I think I know what you are saying but I am having a difficult time with the implementation.

0 Kudos
Message 6 of 9
(6,479 Views)

Yes. You need to use an accessor any time a VI needs to access data outside the class that owns that VI, even if the owning class is a child of the class that contains the desired data. A VI only has direct access (through unbundle) to the private data of the class that owns it, not to any other data in the inheritance chain.

 

If you are frequently accessing several parent data items at the same time, you can create an accessor that returns several elements at once, or you can bundle them into a cluster within the parent data, and return the entire cluster. Or, if you need to manipulate the parent data somehow, then you might consider creating a method in the parent that does the appropriate operation.

 

If that's still not clear, it might help if you can upload a diagram or VI that shows where you're having problems.

Message 7 of 9
(6,475 Views)

I generally go a step further.

 

I create accessor VIs for whatever data I want to have access to in any given class.  Using that data, I only ever use the accessor VIs or property nodes instead of directly bundling and unbundling, even if it's data from the current class.

 

This way you can handle changes int he underlying data representation much more easily when changes occur.

 

In other words, the ONLY time I use a raw bundle and unbundle in my classes is within the accessor VIs.

 

Shane.

Message 8 of 9
(6,453 Views)

Thanks Shane and Nathand!!!

 

Here was my solution (I finally got it)

 

classes.png

 

According to Shane I could have created a child static accessor as well and then possibly modified the set and get Data. I have never used property nodes instead of accessors. My first thought is that it doesn't increase read ability and may incur more memory. But I could defiantly see how it could make things more scalable. That is something that I may play around with later.

0 Kudos
Message 9 of 9
(6,428 Views)