Jump to content

A case for classes in cases and case classes


Recommended Posts

I am a fan of statically typed programming. I'm also a fan of message passing to share data between parallel sections of code. 
 
Because of this, I wish this idea would get more traction:
 
And here's why-
 
Suppose I have modules in my application that broadcast messages using a User Events. Any other code module can register for these events and receive the messages. But if these messages can carry different data, I have no pretty, typesafe, way of guaranteeing at compile time that the message carries the appropriate type of data.
 
 
post-30070-0-87766300-1379020219_thumb.p
 
I could dynamic dispatch on a message Do.vi, passing in a class that inherits from some class the Do.vi calls a dynamic dispatch vi of.
 
post-30070-0-47318500-1379020306_thumb.p
 
For each event registration I have to create another class. Including interfaces in LabVIEW OOP would alleviate this. However, I think the above linked idea provides a cleaner implementation.
 
post-30070-0-89212200-1379020307_thumb.p
 
Another option I have is to attempt to downcast the parent message class to all of its children, and do something once a downcast is successful. This works fine, but if there are a lot of child messages this design pattern becomes large. The linked idea would achieve this in a much more compact, readable way.
 
post-30070-0-72684500-1379020379_thumb.p
 
I'd also like case classes in LabVIEW - classes with no private data or methods, that include child classes beneath them in tree fashion in the project explorer, making it very clear what possible concrete data types can manifest at runtime.
 
post-30070-0-63356400-1379020845.png
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.