LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP Interfaces - how to call the UI method on a parent Interface?

Solved!
Go to solution

Hello, I'm hoping to get some guidance on how to call a method on a parent INTERFACE rather than a parent CLASS (for which there is an existing Call Parent Class Method.vi).  

 

Here is my use case spelled out in UML...

 

NateUT_0-1693837870625.png

 

I have a generic DeviceBase class which can be specialized into either a Voltmeter or Thermometer, each of which has concrete implementation code for two unrelated protocols (Protocol1 & Protocol2), the private data required for each protocol (Protocol1_Ref & Protocol2_Ref) are accessed by the concrete children by inheriting from Device_Protocol1 or Device_Protocol2.

 

The Voltmeter and Thermometer user interfaces are agnostic to their protocols, so I'd like to design a "UI.vi" for a Voltmeter and a "UI.vi" for a Thermometer and not have each of the 4 concrete classes contain their own "UI.vi", two of which are essentially duplicates to maintain.  Thus, it seems to make sense for these "UI.vi" methods to be at the INTERFACE level along with the other generic functions (like MeasureVolts.vi or MeasureTemp.vi) which are overridden by the concrete classes.

However, if I have an object of Voltmeter_Prot1, I can't figure out how to call the associated Voltmeter Interface's UI.vi (which would contain a button that generates a call to Voltmeter Interface's MeasureVolts.vi that would then be overriden by Voltmeter_Prot1's concrete implementation of this method).  I understand how to do this if the Parent is a Class by using the "Call Parent Class Method.vi" but there doesn't seem to be any corresponding VI for calling a parent Interface's method.   Nor can I figure out a way to do this by extracting the path or name of the Interface, since there doesn't seem to be a VI available to list the entire inheritance hierarchy of a class programmatically.  Nor can I do this by defining additional Classes called VoltmeterBase and ThermometerBase to contain the UI.vi implementations, since then I would have to use multiple inheritance which isn't supported by LVOOP. 

 

Certainly open to other high-level architecture suggestions as well if calling a parent Interface's method isn't possible via a concrete class. 

Thanks in advance!

0 Kudos
Message 1 of 5
(750 Views)
Solution
Accepted by topic author Nate@UT

Ahh... I was well aware of the Decisions Behind the Design whitepaper for OOP & CLASSES (2006) but not of the newer corresponding paper for INTERFACES (2020), which spells out an answer to my above question... i.e. that it's not possible. 

LabVIEW Object-Oriented Programming: The Decisions Behind the Design - NI

LabVIEW Interfaces: The Decisions Behind the Design - NI Community

Message 2 of 5
(675 Views)

Not sure where you're seeing that doesn't work. Interface VIs absolutely can be called as long as they're not overridden and even if they are when a call parent method is included in the child method, it'll call the VI in the parent, even if it's an interface. Interface VIs can absolutely have implementation (other languages would call it default implementation) and they can definitely be run.

 

Perhaps just have a play with some simple examples and provide an example that doesn't work the way you need it to.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 3 of 5
(631 Views)

Sorry, didn't mean to imply that an Interface's method couldn't be called or contain implementation code (default implementation) at all... but the key is that IF they are overriden, then the concrete child class has no way to call its parent Interface's default implementation like it can for a parent Class's override (using the Call Parent Class Method.vi).

0 Kudos
Message 4 of 5
(622 Views)

Like I said, call parent method works when the parent is an Interface. Not sure what you're talking about without a more concrete example.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 5 of 5
(607 Views)