LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Polymorphic Object??

 


@MacDroid wrote:

 

parent class TOP has methods X, Y, Z.

 

Child A has X, Y, Z

 

Child B has X, Y, Z, W

 

A & B are loaded into an array and X, Y, Z can be accessed with To Specific with the target input wired to a TOP object.


 

X,Y and Z can be accessed via a Parent type wire (regardless of the type)  If they are dynamic dispatching the proper class's method will be called.  You can also call the parent method from within the child method.

 


@Ben wrote:

@MacDroid wrote:

So in the image, I can call (blue 1) from within (yellow1)?


 

I don't know what your color scheme is so I will ignore that part.

 

You have the parent TOP.

 

In your code you invoke X then Y then Z using the methods from TOP.

 

If you code B's version of X such that it calls X from TOP then (still inside of B's X) invokes W when the type flowing on the wire is of type B, then the over-ride VI of B will be invoked.

 

Ben

 


The point here is that in order to call W, you need a wire of type Child B.  This can be accomplished by using a To More Specific node, with Child B wired to the top.

 

If it doesn't really make sense to call W from within X,Y or Z and you don't want to use the To More Specific, you could make fat classes, such that they all have W but the only meaningful implementation is provided for Child B.  Then, like X,Y and Z, W could be called on a Parent wire.

 

Your images are confusing.  It'd be far more useful if you had icons that said what class they were, and what method.  

 

 

--
Tim Elsey
Certified LabVIEW Architect
Message 41 of 45
(686 Views)

Yeah I wrote the question and the origianal X,Y, etc description, then copied the code I was toying with.

 

But in the image, the blue vi is actually a member of the object that is also blue. The blue object being a child of the yellow object.

 

 

0 Kudos
Message 42 of 45
(676 Views)

@MacDroid wrote:

Yeah I wrote the question and the origianal X,Y, etc description, then copied the code I was toying with.

 

But in the image, the blue vi is actually a member of the object that is also blue. The blue object being a child of the yellow object.


Is the blue VI what you were calling W?  If not, there's no reason for the To More Specific.

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 43 of 45
(669 Views)

Yes.

 

The Obj_BKP1786B implements W

 

Obj_Equipment is the parent and does not implement W

 

So, if I understand, other methods of Obj_BKP1786B, that may actually be inherited from Obj_Equipment, can call W without a To Specific.  (Is that correct?)

0 Kudos
Message 44 of 45
(665 Views)

@MacDroid wrote:

Yes.

 

The Obj_BKP1786B implements W

 

Obj_Equipment is the parent and does not implement W

 

So, if I understand, other methods of Obj_BKP1786B, that may actually be inherited from Obj_Equipment, can call W without a To Specific.  (Is that correct?)


Yes that's correct.  For example, the Child implementation of X could call W as a subVI, because inside Child.X the data type on the class wire is actually the Child type and not the parent type.  

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 45 of 45
(660 Views)