LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview Interface Override Behavior

Solved!
Go to solution

I have a class which inherits (Blue) an interface (Purple) which inherits an interface (Orange). Orange has a method "Do.vi" which Purple overrides (Blue does not implement this method).

 

I want to call this method, passing in Blue. My expectation is that it it should dispatch to the "nearest" implementation, ie Purple. However, I am seeing that it is skipping Purple and going straight to Orange.

skaley_1-1632770390983.png

 

 

Whats more, when I try to specifically upcast to Purple and yet it still dispatches to Orange at runtime

 

skaley_2-1632770418364.png

 

Am I wrong to assume that it should dispatch to the "closest" child implementation?

 

Example code attached  (LV2020, reproduced in 2021)

 

0 Kudos
Message 1 of 4
(139 Views)
Solution
Accepted by topic author skaley

I don't have 2020 to try it out but I believe this is because Green inherits from Orange as well.  If you were to remove Green's inheritance from Orange, then it should work as you expect.  I think this is because Green has a "virtual" Do.vi instance, i.e. it refers it to Orange, and the system can't tell which of either Green or Purple to call since both can call it, so it calls Orange because there's only the one instance of it.

 

I would also note that the upcasting there doesn't actually do anything other than change the color of the wire on the diagram.  Part of the core LVOOP design (and OOP design in general) is that you can never just "change" from one class to another.

Message 2 of 4
(105 Views)

Great catch! That was the issue, thank you! 

0 Kudos
Message 3 of 4
(97 Views)

FYI If you haven't read it, this is an interesting resource into the decision making behind the behavior.

 

https://forums.ni.com/t5/Community-Documents/LabVIEW-Interfaces-The-Decisions-Behind-the-Design/ta-p... 

Message 4 of 4
(95 Views)