06-18-2009 05:51 PM
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.
Matt06-18-2009 09:34 PM
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:
06-19-2009 12:11 PM
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.
08-15-2013 03:21 PM
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.
08-15-2013 03:44 PM
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?
08-15-2013 05:19 PM
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.
08-15-2013 05:31 PM
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.
08-16-2013 02:59 AM
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.
08-16-2013 11:05 AM
Thanks Shane and Nathand!!!
Here was my solution (I finally got it)
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.