Sunday, August 13, 2006

The Class: the Black-Box Cluster Typedef

Classes are fundamental components of object-oriented programming.

In LabVIEW 8.2, you can think of a LabVIEW class (in an extremely simplified view) as a cluster and the VIs that operate on it.

To VIs outside of the class, an object (an instance of a class) is a black box... or, more accurately, a blue cube. They cannot directly access an object's private data (the elements of the cluster).

VIs that are members of the class can bundle and unbundle the class data as if it were an ordinary cluster.

This is called encapsulation.

So, what is this good for? Lots of things, but I'll only list two here:

  • Data modification choke points. If you want to set some probes to find out where a private data element is changing, you know you only have to set them in VIs in the class.

  • Interface stability. If you decide to change your private data (e.g. adding a new element), none of the VIs that use your class have to change, unless they want to use the new element.

You might argue that you could achieve both of these benefits by using a cluster typedef and a set of VIs that read/write the values of each element. And I would agree. But without using classes, there would be nothing to prevent someone from writing a VI that circumvents your plan and accesses the cluster directly.

And, of course, there's much more to object-oriented programming in LabVIEW, as we'll see in future posts...



Blogger ~,~ NJKirchner said...

Any chance NI would let you release the code for the "getting started" dialog. It's just a great use case that many people can see a full implementation on how it should/could be done.

12:42 PM, August 14, 2006  
Anonymous Anonymous said...

Thanks for doing this Christina.

1:52 PM, August 14, 2006  
Blogger TonP said...

Good intiative Christina!
Had to read the link out load to get the title right.

And besides releasing the code of the 'getting started' I wonder if it is possible to add your own 'regions'. I hardly ever use the right hand-side but love to add a seperate recent project and recent file section. Or a template section, or just some favourites or...

I think with OO you can do this better than before!

11:34 PM, August 14, 2006  
Blogger Christina said...

I'm working on publishing the Getting Started VIs that I showed at NIWeek. With this new, object-oriented version, you will have control over the links through an XML file, so you can put favorite web links on the right-hand side.

Thanks for reading!

8:30 AM, August 15, 2006  
Anonymous Carsten said...

Interesting, I'd really like to use some of these features...

BTW, I'd rather compare the new OO thingies to using programatic variables, i.e. VI that save variables and provide an interface to read, set, do something else with the elements. Here you even have (strong) encapsulation! The problem/advantage of those is, that they break data flow usually (well, you could implement data flow, though, if you need it)...

10:01 AM, August 15, 2006  
Blogger Christina said...

I will probably get to the "programmatic variables" concept eventually. If you are already familiar with "by reference" object-oriented design and want to learn about how that works with LabVIEW 8.2, I suggest you read this white paper:

1:03 PM, August 15, 2006  

Post a Comment

<< Home