LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array of child class in private data of parent class

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

0 Kudos
Message 1 of 20
(4,020 Views)

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

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 20
(4,010 Views)

@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).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 20
(3,992 Views)

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. Smiley Sad 

 

Thank you guys!

Regards

KB

Message 4 of 20
(3,939 Views)

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.


GCentral
Message 5 of 20
(3,934 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 20
(3,917 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 20
(3,905 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 20
(3,897 Views)

Agree with other posters, this is a bad design. A parent class should never depend on its children.

0 Kudos
Message 9 of 20
(3,885 Views)

@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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 20
(3,869 Views)