07-01-2021 02:21 AM
Hi everyone,
I am very new to OOP in LabVIEW.
My question is: I created a Parent class and a child class; so far so good. But now after changing something in Parent.ctl, is it possible to apply this change to Child1.ctl?
Or it's not possible update something after creating the Parent Class?
regards
Sinan
CLD
07-01-2021 07:47 AM
That added data at the parent level does not need to be duplicated in the child. It is inherently in child, because it inherits it from the parent.
07-01-2021 08:00 AM
Right click on the parent.lvclass and create "VI for data member access"
Create read and write methods, I also allow to be set via property nodes.
Then within the child you can use the property nodes (or the accessor VIs) to set and get the data of the parent.
07-02-2021 02:03 AM
Thanks.
Could you please attach your project? I cann't understand where within child to access the ParentClass
07-02-2021 09:42 AM
Children classes inherit everything from the parent class. That means all data and methods. In LabVIEW however, the child class does not have direct access to the class private data which is the class control. If the parent wants to provide access to the data it will need to provide accessors which the child class can then use to access the data. Because the parent implements the accessors to the data it controls how it can be accessed. If only a read accessor is provided the children classes will only be able to read the data. Then in your code simply drop the parent class accessor unto the block diagram and your child can now use the data.
07-06-2021 06:55 AM
Hi Mark,
Thanks for your help.
Could you attach a LabVIEW Example please? Because as I said before, I am very new to OOP.
07-06-2021 08:15 AM
But if I have 20x Data members, should I create 20x Accessors? That is not a practical solution !!
07-06-2021 08:59 AM
40x if you need read & write 😅
You should cluster your data where it makes sense to reduce the number of Accessors.
Creating Accessors is fairly automated:
07-06-2021 11:10 AM
@Sinan_Ismael wrote:
But if I have 20x Data members, should I create 20x Accessors? That is not a practical solution !!
As mentioned, it's fairly simple and automatic, but 20 accessors might signal a problem in design. (Or not, i like them as they allow me to use property nodes to read and write the data)
But in general a root class has methods that use the root class' data, and a child do some extra stuff and use the parents methods. Often the child doesn't need to use the parent data directly, and some would argue it's wrong.
What are you trying to do?
07-22-2021 02:28 AM
I want to write a program to test a sensor. This program will be the base to test other senors in the future. It looks nice when I create a ParentClass for this sensor and later the other senors inherits from this sensor.
But at the same time, I want it to be more flexible; I mean many hardware can be used. In other words we have different types of Daqs. I want my software to be flexible with all types of daqs.
In this case should I create a Class for the sensor and another class for Daq??? Actually I do not think that's a good solution!!!