LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

class dynamic dispatch - allow only children, not nephews

I am relatively new to LVOOP. I have a family of 3 generations of classes that inherit from grandparent to parent to child. My application has 1 grandparent, 2 parents, and each parent has 3 children.

 

Each of the parents is handled in it's own loop. I want the dynamic dispatch (DD) VI to be only able to execute the children or the parent. If the parent sibling or his children (nephews) are called, I want to generate an error (compile-time preferred, but runtime if necessary). In my application, the attempt to process a parent sibling or nephew is (technically) possible, but always a bug in my design pattern.

 

Are there any native tools in LV to restrict DD handling?

0 Kudos
Message 1 of 7
(2,399 Views)

Below is a diagram of what I mean.

 

2013 LV Classes diagram.PNG

0 Kudos
Message 2 of 7
(2,394 Views)

Then you need to define the DD VI in Parent 1 and Parent 2 VIs, not in Grandparent.

 

Yeah, there'll be code duplication but otherwise you won't get what you're looking for.

 

Shane.

0 Kudos
Message 3 of 7
(2,385 Views)

I have an instance of the DD defined at the grandparent level. All it does is generate an error with specific info about which class was incorrectly used.

 

Are you suggesting that if I remove the DD subVI at the grandparent level (and keep 1 for each parent), my goal will be accomplished?

 

 

 

There is another facet of my application that may be important. I am using these classes for messaging among various queue-driven state machines. Thus, I don't want one QDSM to attempt to implement a message designed for a different QDSM (and likely attached to different hardware).

 

The grandparent generation is part of a common-use library that is shared among many applications, so it must be generic. The parent and child generations are application-specific.

 

In order to continue to make use of common shared code, the class wire input to the DD subVI for each state machine must be of grandparent class. Thus, I cannot simply set the DD subVI to parent generation only.

 

Am I forced to give up the control of designating which children vs nephews can be dynamically dispatched to take advantage of code reusability?

0 Kudos
Message 4 of 7
(2,381 Views)

Can you restrict access somewhere else? It seems like you should make your queues carry the appropriate parent type. You'll still be able to call the grandparent methods, but you'll get a compile-time error when you try to put an object onto the wrong type of queue.

0 Kudos
Message 5 of 7
(2,370 Views)

Your suggestion of using the parent class for the queues is valid. It was the first approach that I did. But when I attempted to abstract sizable portions of my code to the common-use library, I was forced to use the ancestor (grandparent) class.

 

So to try to take advantage of class inheritance and software reuse, I'm looking for a way to restrict execution of DD subVIs to a particular branch of the heirarchy. Obviously, I can embed some information within the class data and do this myself. I want to know if there is any way to natively accomplish this in LV.

0 Kudos
Message 6 of 7
(2,341 Views)

Yeah, you create a new message dispatcher which is strictly typed to the parent.  If you want to send a global message, use the grandparent method, if you want to make sure the right type is arriving, use the parent method.

 

There's no automatic way to do it.  You can't have strict typing and a single method, that just doesn't work.

 

Shane.

0 Kudos
Message 7 of 7
(2,334 Views)