LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

In search of a minimal LabVIEW class example

Solved!
Go to solution

Overly simplified sets of classes and class instances like those shown in the images below were very helpful when I started learning object oriented programming.  Has anyone come across or would anyone care to write a bare-bones LabVIEW example project based on one of these examples?  I know the OOP concepts but I'm implementing them in LabVIEW for the first time and haven't quite grasped the nuances of the various objects.  Correct me if I'm wrong but I think the objects are intended to be used as follows:

 

The .clt file contains the private class data

VI  (for implementing methods)

Virtual Folder (contain instances of the parent class)

Property Definition Folder (provide access to the class properties)

VI from Dynamic Dispatch Template (this is for implementing polymorphism)

VI from Static Dispatch Template (this is for implementing the parent method as it is written in the parent class)

VI for Override (this is for overridding the parent method in the child class)

Control (hmm, not sure what this is for)

 

It would be ideal to demonstrate the use of each type of class object.

 

 

Here are 3 examples of a base class along with multiple instances of the base class.  The source for each example is linked below the image.

 

Shape Class.png

5.1 The abstract Method and abstract class 

 

 

Person class examplePerson class example

Figure 2: Class diagram and inheritance. 

 

 

Animal class exampleAnimal class example

How to instantiate objects super class and sub-classes 

0 Kudos
Message 1 of 4
(1,029 Views)

Don't have access to LabVIEW at the moment, but I can help you with some misconceptions. It looks like you are just listing the right-click menu on the class itself, which doesn't really help you understand the intent.

 


@skinnedknuckles wrote:

Correct me if I'm wrong but I think the objects are intended to be used as follows:

 

The .clt file contains the private class data

VI  (for implementing methods)

Virtual Folder (contain instances of the parent class)

Property Definition Folder (provide access to the class properties)

VI from Dynamic Dispatch Template (this is for implementing polymorphism)

VI from Static Dispatch Template (this is for implementing the parent method as it is written in the parent class)

VI for Override (this is for overridding the parent method in the child class)

Control (hmm, not sure what this is for)


  • The Class Control does store the private data of the class. This is a collection of all class private fields. LabVIEW controls are semantically similar to structs or similar in other languages. Class private data is always that - private. Unlike other languages, LabVIEW enforces that all class data must be private, therefore requiring accessor methods to get/set that data.
  • VIs are used for implementing logic (ie methods), since that's the only LabVIEW construct that executes code. For a VI to be considered a method of the class it really needs to operate on the class data in some way (although you can say that "static" class methods don't need to). LabVIEW has a specific term for VIS that access the class private data - Accessor methods.
  • Virtual Folders are an organizational tool only and have no bearing on classes. You can use them in projects and project libraries as well. Otherwise put them out of your head for the purposes of understanding OOP in LabVIEW.
  • Property Definition Folder is a semantic way of visualizing accessing fields as Properties (ie treating method calls to get/set fields as an API-defined field-like access). LabVIEW doesn't permit access to the private fields externally, so the only way to access is via accessor methods. Properties in LabVIEW provide an alternate way of calling these accessor methods using a property node. This is conceptually similar to other languages eg. C#. You can get by without using Properties at all.
  • "VI from xxxx" are IDE short-cuts for creating new VIs that operate on class data (operating on the class control and returning the modified version via the class indicator). The only difference between static and dynamic dispatch is what method will be called at runtime and thus what private data the method will access. You could also create these methods manually by creating a new VI and adding in the class controls/indicators.
  • VI from Over-ride is indeed the implementation of the child override of a dynamic dispatch VI. Its another IDE short-cut to creating a dynamic dispatch VI from a template with the same name as the parent version. Like all short-cuts, you could do this yourself manually.
  • Control is the definition of a struct-like type. It's not related to classes specifically but you can create said types as being owned by the class.

The other thing to bear in mind is that LabVIEW classes are by-value. What this means in practice is that when you copy the wire for an object (which is basically just its private data fields plus some data indicating it's type) you get a copy of that object. This is why class methods have a class in / class out template. It also explains why LabVIEW classes don't have a constructor - placing a constant of the class on the block diagram *is* the constructor for the class, in addition to any other init methods you expect the caller to use.

I'd suggest using the hints I've given you above to try one of the examples you listed, perhaps the common shape one.

Message 2 of 4
(1,017 Views)

This is an excellent introduction for experienced OO programmers who are new to LabVIEW.  THANKS!

0 Kudos
Message 3 of 4
(973 Views)
Solution
Accepted by topic author skinnedknuckles

If you're okay with YouTube videos, this one walks you through the creation of the "shape" class.  The image below shows the resulting LabVIEW project.  It's a bit fuzzy but it will give you some idea of what it looks like at the end.

 

Introduction to LabVIEW Object Oriented Programming 

 

Shapes.lvprojShapes.lvproj

0 Kudos
Message 4 of 4
(971 Views)