09-05-2019 08:42 AM
Hi,
I've got an issue with my LV OOP structure. For example: There is a parent class called Measurement Device.lvclass, a child class (inherit from Measurement Device) called DMM.lvclass, and child classes called Keithley or Fluke inherit from DMM.lvclass. As I want to use multiple DMM in real world, I would have to put an array of DMM.lvclass in my Parents class private data (Measurement Device). And here is the problem: The error window said that the arrays default data is illegal for the private data of this class. Of course it is an empty array of DMM class.
Did anybody know what's the matter?
Regards
KB
09-05-2019 08:49 AM
You would need that to be an array of most-generic-level "Measurement Device" objects. You'll be able to *populate* that array with any combo of objects that inherit from "Measurement Device". So you can have 2 Flukes and 1 Keithley or whatever in the same array.
On the block diagram, they "travel as" generic parent-level objects, but at run time they "behave as" specific child-level objects.
-Kevin P
09-05-2019 09:07 AM
@kaba2005 wrote:
As I want to use multiple DMM in real world, I would have to put an array of DMM.lvclass in my Parents class private data (Measurement Device).
Why? I don't follow that logic. Your parent class is to represent only a single device.
Nothing says you cannot have multiple instances (objects) of the Measurement Device class. You can easily store each object in an array, cluster, variant attribute, etc. You just use whatever you need to get the exact instance you need (index, unbundle, get attribute, etc).
09-06-2019 02:54 AM
Hi,
you're right. The parent class represents just a single device. The DMM was just an example. In my case classes an source code still exists and works fine. I want to add our own Measurement rig (19" case design backplane and multiple cards for different signals like SENT, PSI5, PWM, ...).
So, multiple objects of the Measurement Device.class is not a solution, because the main source code has to be modified to e.g. read multiple devices.
Anyway, I found the answer: You can not define classes in Labview recursively! Maybe it is possible to define the reference to an object in the private data...
Unfortunately the most LabVIEW Programmer are not familiar with OOP.
Thank you guys!
Regards
KB
09-06-2019 03:03 AM - edited 09-06-2019 03:04 AM
I'm with the above posters: you can certainly consider an architecture with multiple measurement devices in an array.
It sounds like what you want is a class like "Measurement Rig", for which you instantiate a single object, and that this object has some knowledge about a range of different devices that it contains (DMMs, Power supplies, etc).
In this case, the key point would be that a "DMM" or a "Measurement Device" is not a "Measurement Rig", whilst you could reasonably claim that a "DMM" is a "Measurement Device". So by having a Measurement Rig contain an array of Measurement Devices, which do not inherit from Measurement Rig, you avoid "recursive" definition of classes (I'm not sure this really is recursion so much as a cycle of references, but anyway...) and have a simplish structure that represents your setup.
Since LabVIEW has only the equivalent of public, single inheritance, you always want a child to satisfy the '<child> is a <parent>' relationship.
09-06-2019 08:22 AM
How would such a structure look in UML? It sounds like a circular reference to me.
Usually an object knows nothing of the other objects unless it's an owner or manager, and a single instrument is neither. If you really want to break the isolation principle of OOP you can have a named Queue of base objects in the top class and add to the queue in a child Create function. Since it's named it'll be the same queue for all objects and they can all know of each other.
As mentioned the normal solution is to have an InstrumentManager/Container which knows of all instruments.
/Y
09-06-2019 08:40 AM
Inheritance - Is a kind of
Composition - is composed of
Two different patterns.
While it is possible to recursively define a class that is composed of itself, you do NOT want to have to single step into such a beast when trouble shooting.
Ben
09-06-2019 09:01 AM
@Ben wrote:
Inheritance - Is a kind of
Composition - is composed of
I'm not a fan of circular definitions. The more common terminology is:
Inheritance = is a (ex: a dog is a mammal)
Composition = has a (ex: a dog has a tail)
So what the OP is proposing is a DMM has a DMM. Nope, that makes no sense to me.
09-06-2019 09:34 AM
Agree with other posters, this is a bad design. A parent class should never depend on its children.
09-06-2019 10:17 AM
@crossrulz wrote:
...Inheritance = is a (ex: a dog is a mammal)
Composition = has a (ex: a dog has a tail)
...
You said that so much better than me.
Thank you!
Ben