12-14-2023 07:05 AM
Why are the GOOP classes implemented with a U32 as Ref in the Cluster of private data? Why not put the class DVR directly into the Cluster of private data and have a much simpler object creation like below?
Solved! Go to Solution.
12-14-2023 07:27 AM - edited 12-14-2023 07:34 AM
Hi CuriousSwede,
Simply to allow a class to contain objects of the same class (or subclasses) in its private data.
Try dragging the class in its own private data, you will get error:
"The private data control defines the default value for a class. This private data control has values set as the defaults that are illegal. Illegal default values include: any value of this class itself, any value of any child class, any class that has not been loaded into memory, and any class that uses this class as a member in its own private data control. If you do not see the problem value immediately, you might check the default value of any variant controls in the private data to make sure their default values are not the problem."
So flattening the DVR to a U32 is a workaround to avoid this error.
This is particularly useful when you have objects linked together like in a graph. For example you may have an object "Node" that has a private field "Neighbors[]" which contains a list of other Nodes that are connected to the current Node. Without this flattening to U32, you would have a sort of "infinite data type encapsulation".
Regards,
Raphaël.
12-14-2023 04:45 PM - edited 12-14-2023 04:46 PM
Hi Raphaël, and thanks for your answer.
I´m quite new to OOP and your use cases where a class has components of its own class or any subclass, sounds a little bit obscure to me.
But I´m sure you´re right in what you are saying.
12-14-2023 06:23 PM
Imagine a social network that defines a class "Person". Each Person has a property "FriendsList" which is a list of Person, so the same class.
Since these friends are Persons, they also have a property "FriendsList", which is a list Person, etc...
Since LabVIEW wants to have the full description of data types, it would have to infinitely recurse in the Person's private data definition, which is obviously not allowed.
Here is an example of a "Class" that contains an "Unrelated Class". You can see that LabVIEW describes the data type entirely down to the private data of the "Unrelated Class" object:
I let you imagine what would happen if LabVIEW allowed putting a "Class" in a "Class" (edited with paint, this is impossible to have in LV):
And if you wrap your class in a DVR, it just adds a level in the data type, but does not prevent the "infinite type recursion".
Turning the DVR to a U32 is just a trick to hide the actual data type to LabVIEW to avoid this problem.
Regards,
Raphaël.
12-14-2023 11:46 PM
Great answer, I got it. Many thanks! 😊