Friday, September 08, 2006

Dynamic VIs and Override VIs

In order to take advantage of dynamic dispatching, you must have classes with dynamic member VIs.

A dynamic member VI is a VI that
  • is a member of a class and
  • has a dynamic input terminal.
A dynamic input terminal is the one that determine dynamic dispatching at run-time.

You can create a dynamic member VI by right-clicking on a class in the project tree and selecting New┬╗Dynamic VI. You can also create one by creating a normal VI and configuring it to have a dynamic input. The New Dynamic VI option is just a convenient time-saver, creating the VI from a template and configuring it with an input and output of the selected class.

Should all class member VIs be dynamic? Probably not. The overall design will be clearer if only the VIs that you intend to override in child classes are dynamic. Note that you can easily change a member VI between dynamic and non-dynamic by configuring the connector pane terminals. In previous versions, a connector pane terminal could be Required, Recommended, or Optional. In LabVIEW 8.20, there is a new option called Dynamic Dispatch.

An override member VI is a dynamic VI that has the same name as a member VI in one of the class's ancestors. Again, there is a right-click New option on the class in the project tree that helps you create them.

A dynamic VI and its override VIs in child classes are a set of VIs that perform the same operation for a hierarchy of classes. We call the operation a method (from classic OO terminology), which means a method on a class is a VI or set of VIs.

Let's look at an example. In our new Getting Started window, we have an object to manage each of the link buttons. All of these objects are instances of classes that inherit from Link.

In the Link class, we have a dynamic VI called This VI parses a section of an XML file to get the data values that are stored in Link's private data cluster.

Now, if we look at the Web class, which inherits from Link, it also has an This VI parses the value that the Web class knows about (URL) from the XML. But it needs to do more. It needs to have its parent class do whatever work it does for InitFromXML. So it uses the Call Parent Method function.

This kind of override VI extends the functionality of its parent class.

If you look at another VI in Web,, you'll find an override VI that replaces the functionality of its parent class (because it does not use the Call Parent Method function).

So, in summary of my point today, dynamic VIs allow you to extend or replace the functionality of a class in its child classes.



Blogger ~,~ NJKirchner said...

"More than 1 dynamic dispatch terminal"??!!
What happens w/ that and how can we use that capability to do cool things??

10:28 AM, September 11, 2006  
Blogger Christina said...

Wow, that's odd, I could've sworn I responded to this comment last week, but my comment is gone...

Norm, thanks for the catch. That mistake was a mental hiccup on my part. I corrected the original post.

10:52 AM, September 19, 2006  

Post a Comment

<< Home