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 5
(1,624 Views)
Solution
Accepted by 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 5
(1,590 Views)

Great catch! That was the issue, thank you! 

0 Kudos
Message 3 of 5
(1,582 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 5
(1,580 Views)

There's one more bit I want to add in case someone else stumbles across this answer in the future: LabVIEW interfaces can't override classes. Interfaces can't inherit classes and, the part that matters here, inheriting a class and an interface always gives the class priority. 

 

Since (Green) is a class, its "path" to the vi becomes the active one, and the parallel interface override is ignored even though (Green) itself doesn't actually implement the vi.

 

This is an interesting implication I hadn't considered, but it makes sense based on the rules laid out in the Behind the Decisions on Interfaces (whatever it's called) document linked above.

0 Kudos
Message 5 of 5
(1,355 Views)