08-17-2022 08:10 PM
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.
5.1 The abstract Method and abstract class
Person class example
Figure 2: Class diagram and inheritance.
Animal class example
How to instantiate objects super class and sub-classes
Solved! Go to Solution.
08-17-2022 09:01 PM - edited 08-17-2022 09:31 PM
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 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.
08-18-2022 10:13 AM
This is an excellent introduction for experienced OO programmers who are new to LabVIEW. THANKS!
08-18-2022 10:23 AM
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.lvproj