LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Taggart

Allow us to use interfaces for class methods that use properties.

Status: New

I just realized that when creating an interface you cannot create property node folders.

 

You can see from the pictures below that option is missing from interfaces.

 

second.pngfirst.png

 

You can also see from that screenshot that it is possible to have property folders in interfaces and they work just fine. You have to edit the xml to do that, but it works. So it is implemented, it is just removed from the IDE.

 

Now I talked to Darren and he seemed to think the original reasoning was "Well property nodes are for storing things in the class private data and there is no private data with an interface, so you don't need them." I can't really argue with that logic, however, there are times when an existing class uses a property node and you want to create an interface that includes that method. For example you may have multiple instruments that have a VISA ref property. You currently can't create an interface with that "write VISA ref" VI (without editing the xml.) If you create a method with the same name/conn pane and it is not in a property folder, the compiler complains. Now you could just go back and edit the original class and remove the property node and just use a regular method. However then you break every piece of calling code that is using a property node.

 

Here is a use case, which I think is fairly common - it happens to me a lot:


I inherit some code. It is using some particular instrument (Oscope, DMM doesn't matter) They want to support another similar instrument (maybe newer version of the DMM).

 

The instrument code is wrapped in a class. Great. As a first step, I can refactor. I can create an interface that has all the same methods and make the code rely on the interface. If it is a class wrapped in a DQMH module, all I have to do is replace the object in the Shift register with the interface and somewhere set the concrete class in the initialize. It all works exactly the same as before, but now I have an interface.

 

Then I create another class that implements that interface and add some logic to pick which one - some kind of factory. Done. I've made very minimal changes to the existing code and it now supports a different instrument. This is the holy grail of OOP. I create a new class and just inject it and everything works.

 

Not so fast. NI has decided I shouldn't be able to do this if the class uses a property node (oh no!) why? I should be able to have 2 classes that both have the same property. Sure the data's not getting stored in the interface, but what does that matter?

 

It does matter to the compiler. If I want to do what I proposed above and the original developer used property nodes anywhere this doesn't work directly. I have to either do some xml hack on the interface or I have to replace all the property nodes in the calling code with subvi calls and then go edit the class and remove the property folders. Why?

 

It seems like all that is needed is enabling the right click menu, because if you manually edit the xml, it all works. That is already implemented for classes, so I imagine the fix would be rather simple.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
3 Comments
Taggart
Trusted Enthusiast

I guess a 3rd workaround is to create seperate method in the class that duplicates the VI that makes up the property node but isn't itself a property, and then create the same method in the interface. That could work, except that in existing code, if you wanted to replace the class with the interface in the calling code, it would break everywhere you are using a property node.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
mjhakkar
Member

Maybe my older idea now makes more sense in context of your idea (https://forums.ni.com/t5/LabVIEW-Idea-Exchange/OOP-Interfaces-automate-data-accessor-code/idi-p/4199...)

In short, if there's interface property nodes then have a tool to generate matching data type to class private data.

--
Marko H

OptoFidelity - Enabling Smarter Future

Tampere - Espoo - Oulu - Cupertino - Redmond - Zhuhai

IlluminatedG
Active Participant

We have an application that is based largely around the use of Property Nodes and their functionality for automatically dereferencing DVRs of classes. That mechanism doesn't work at all for Interfaces. Instead of being able to leverage interfaces to clean up some of the functionality that overly leverages inheritance we have to basically start over if we want to clean it up (really, we need to) and completely redo how the program state is managed in addition to cleaning up the inheritance hierarchies.

~ G stands for Fun ~
Helping pave the path to long-term living and thriving in space.