02-04-2016 02:08 AM - edited 02-04-2016 02:36 AM
Hello,
I am trying to use OOP for my DAQ application. I have different hardwares for analog and digital I/O. I am creating one parent class named DAQ.lvclass. This class has four childs: Analog In, Analog Out, Digital In and Digital Out. I am trying to invoke VIs of child class from parent class. For this I am trying to cast the parent class to its child using "To more specific class" function. But I am getting error mentioned below.
Error 1448 occurred at To More Specific Class in DAQ.lvclass:DAQ Main.vi
Possible reason(s):
LabVIEW: Bad type cast. LabVIEW cannot treat the run-time value of this LabVIEW class as an instance of the given LabVIEW class.
How can I handle such cases where I have to call child VI from parent member?
I have attached snapshot of two VIs. 1. DAQ Main: This is the main parent class VI which manages all functions. 2. Read Analog Input: This VI tries to cast the parent class to its child class and child vi reads value from DAQ task. I am getting error out of second VI.
Kindly help.
Solved! Go to Solution.
02-04-2016 02:54 AM - last edited on 11-15-2024 02:29 PM by Content Cleaner
You should definetly read/listen to introductions to LVOOP like this webcast.
Dynamic Dispatching is the "magic word" you are looking for.
Norbert
02-04-2016 03:04 AM - edited 02-04-2016 03:05 AM
Thank you for response Norbert_B.
I am not looking for over riding functions. My understanding of dynamic dispatching is to use it to override method of parent. Child classes are performing different functions in this case. I chose to make these classes because I thought I will have data flow on the parent class wire and will not need complex data handling.
02-04-2016 03:16 AM
Honestly, i have NO clue about what you want to do.
Inheritance of classes in EVERY OOD (object oriented design) requires to define commonalities as parent class. Children might add stuff like properties and methods.
If you define children having no commonalities, you made a mistake.
If all children have too many different specific methods, your OOD is lacking.
Example:
Parent defines method A.
Child 1 adds method B.
Child 2 adds method C.
But method B will not be usable on Child 2 while method C won't work with Child 1.
This is an approach which you want to prevent. In any OOP language. This adds unneccessary complexity leading to difficult to maintain code and it is prone to errors.
However, if you going to do this, "To More Specific Class" is the correct type cast. But from your screenshots and the error messages, it is obvious that you narrow down the cast to one specific child only. You have to extend the code to check for the actual child, cast specifically and the invoke the method. That being said, your code increases complexity as you have to add a bunch of case structures which essentially nihilates ALL ADVANTAGES of using OOP.
Sorry to say that.
Norbert
02-04-2016 03:28 AM
Yes Norbert_B, I realised that I have unneccessarily chose the parent child design. I could have easily managed all class individually. My idea was to place data in a single class and share it across the child classes. But it will make things more complex. I will go with individual class design instead. Thank you very much.
02-04-2016 03:37 AM - last edited on 11-15-2024 02:29 PM by Content Cleaner
I think you might find this a useful presentation as it can give you new ideas.
Norbert