LabVIEW Idea Exchange

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

Wire Class To Case Selector

Status: New

It would be useful if we could connect a class wire to a case selector. You will be able to create a case for the children of the class. The internal connection for the selector will return the specific child class. This will eliminate the need to cast to more specific class inside of the case.

 

This idea came from this thread on Lava.

 

original.png

=====================
LabVIEW 2012


12 Comments
drjdpowell
Trusted Enthusiast

Hi David,

It's true that you can use dynamic dispatch to achieve the same thing as this idea.  In my example I could add an "Execute Register Observer Command Message" parent method to my "Message" class and then I wouldn't need the case structure at all.  But there are often reasons not to do that, such as:

 

-- as AQ suggested, you can't modify the parent class because it is a published package (you don't want to customize it)

 

-- your parent class would quickly become bloated with a huge number of virtual parent methods supporting each optional child hierarchy, each one of which loads up all the support software required even if that child hierarchy isn't used.  For example, my "Execute Register Observer Command Message" takes an "Observer Register" object as input.  Putting this method in the parent "Message" class would mean that any project using messages would load up all Observer Register software even if it had no use for it.  The proposed case structure allows me to keep Message class lightweight for use in many projects, with each project adding in specialized message child classes.

atum
Member

I can think of an example where this would be useful in manners dynamic dispatch wouldn't be entirely suitable for.

 

Consider a situation where you may be interfacing with a power supply and you are using class inheritence to abstract the functionality (like setting a voltage) from the particular power supply model. Some of the power supplies you are using have high and low ranging. You would like your UI (which is not specific to one power supply class) to hide the indicator for high or low range based on if the particular power supply has the feature or not. While you could make a getter for something like a "Has Ranging" property (among other solutions), IMO the most elegant solution would be this sort of case structure, though I would just prefer to see the class name rather than a big icon. Also *puts on fancy pants*, it might be more visually appealing to decorate (like wiring an error to the selector) the case structure from the one of the wire colors for the class.

 

It would also be possible to use this idea to create some interesting hierarchy function. For example, the case structure, when several levels of inheritence are available, will execute the case for the most specific class a case is defined for. So, from the example above, if a power supply class was wired to the case selector and was not specifically listed as a case, the case structure would use a case defined for a power meter, but if there was a case for the class representing the particular model, then that more specific case would execute. ( I am not sure if there are many use cases here, just more of a 'while you are at it' idea).