GDS(Goop Development Suite)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement Factory Pattern with By Reference GOOP Classes?

Solved!
Go to solution

Hi all, 
So I am fairly new to Classes and GOOP. I have created a base DAQ Class with specific Agilent, NI DAQ Class. My base Class has a method called Load Child Class which gives me a Child Class reference. But when I wire this reference to dynamic dispatch methods I am getting Error 1556: Reference is in Valid.  The code is as follows: 

 1.Create VI for the Base Class

2. Call method Load Child Class (Factory pattern implemented here) 

3. Call init Class (Dynamic Dispatch function loading my Agilent Class with its Data Cluster) 

Test Case.png

I am assuming that this is because I am not calling the Create.vi for the Child Class. But the Create.vi is not dynamic Dispatch, so even if I had the factory pattern code not as a method but on top of this, I would need a Case structure with an enum to do the Class creation (something I want to avoid). 
So don't know what to do here. 

0 Kudos
Message 1 of 5
(1,405 Views)

Using case structure is a simple and reliable way. I would say, it covers 95% of our needs. However, there are other 5% where the class must be selected dynamically.

You do not attach the code, so it is difficult to understand your need. Do you want to create instance of a class using its path?

_____________________________________
www.azinterface.net - Interface-based multiple inheritance for LabVIEW OOP
0 Kudos
Message 2 of 5
(1,378 Views)

Yes. I do want to create a Class directly based on its Path. My Load Child Class VI is the basic factory pattern. The reason I would like to do this and avoid a case structure is because this pattern has a much better memory usage, wherein at Run time only my required Child Class is loaded in LabView memory rather than all my Classes if I use a case structure. I would think that GOOP developers would have thought about this, because when learning LabView OOP it's one of the first complex topics introduced and there's lots of videos on it as well, but just not with GOOP.

VBajaj_0-1688598758542.png

 

0 Kudos
Message 3 of 5
(1,361 Views)
Solution
Accepted by topic author VBajaj

Ok, you are using Get LV Class Default Value. This node was created for native LabVIEW classes, which have no constructors. GOOP classes have no default value. So, the node creates a constant with invalid refnum; i.e. the created constant does not contain any instance of the class.

 

To create instance of GOOP class corresponding constrictor must be called. But constructor cannot be dynamic dispatch. Try this solution. Dynamic dispatch wrapper is added in each class.

 

I do not use such a solution in my projects, test it extensively please.

 

I use Call By Reference node instead. It does not require additional files but needs manual changes in code of constructors.

_____________________________________
www.azinterface.net - Interface-based multiple inheritance for LabVIEW OOP
0 Kudos
Message 4 of 5
(1,354 Views)

I'm currently working on example code of different design patterns.
It's not complete, but the Factory Design pattern is there.
https://github.com/opengds/DesignPatterns.git

I very rare needs to load classes dynamically, but this example could easily be modified to read form folder if driver is not found in memory.
Cheers,
Mike

0 Kudos
Message 5 of 5
(1,335 Views)