LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Which OOP Pattern to use for my application

Ok, I am trying to figure out what pattern I should use for my application (https://decibel.ni.com/content/docs/DOC-2875)

 

I have different classes for each of the different types of hardware, spectrum analyzer, power supply, etc, with the general "Spectrum Analyzer" being the parent, and then each model (Agilent N9320B) being a child.

 

Now, my thought is that (assuming I have a sub class already), I could select via ring or config file, which Spectrum Analyzer specifically I would want to use for the test.

 

My "issue" is that I wanted to specify which child class to use after the config file, and put the class in a cluster for use in other states.  But if I initialize the cluster with the parent class, I can not "specify" which child class to contiue using (see picture).  I have tried this with both generic class and then the specific parent class, but no cigar. 

 

What am I doing wrong here?

 

undefined

Kenny

0 Kudos
Message 1 of 6
(3,244 Views)

First, are you using dynamic dispatch for your methods? If not you will need to do that. That is what will allow you to create a class of the parent type and then later make the wire refer to a specific type.

 

I would question your class hierarchy a bit since you seem to be deriving very different instrument types from a fairly specific parent type. A power supply has nothing to do with a spectrum analyzer. Usually you would have a generic "spectrum analyzer" class and then derive specific models from that. Then you would have a generic power supply class and then derive specific models of power supplies from that.You could have a generic class called instrument from which you can derive various classes of instruments from. That would work but in your case your base class sounded too specific to derive other instrument types from it.

 

With respect to which pattern to use you may want to look at the HAL (hardware abstraction pattern, more generically called the abstract pattern). For the creation side of things you may want to look at the factory pattern.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 6
(3,237 Views)

Mark, thanks for the reply.

 

Yes, I should have specified, I am using Dynamic Dispatch.

 

I should also clarify that I will have one Power supply, one spectrum analyzer, one signal generator, etc in this test fixture, so I will be using each Generic Parent class (Power Supply, sepc analyzer, etc) and then I was going to somewhow specify which child class I wanted to use after the init state.

 

So my Agilent N9320B class, only gets items from the Spectrum Analyzer class, since it is a spectrum analyzer (which is how I have it now, I guess i did not make that clear enough).

 

Sorry, this is my first venture into OOP, so I might not be totally clear with my terminology.

 

I did some looking at some HAL tutorials, and this seems to be what you are talking about.  http://download.ni.com/pub/devzone/epd/mitigate_hw_obsolescence.pdf

 

undefined

 

 

So I create an Intrument Class (Parent), then a Child class that basically specifies the instrument type (Sig gen, PSU, etc) and then have childern of that child (Grandchild?) which is then the specific model.

 

I also saw in the examples that went with that pdf, they use the Set Class Default to define which child to use based on the config file.  I will try something similar to that.

 

undefined

Kenny

0 Kudos
Message 3 of 6
(3,198 Views)

I'll reiterate what Mark said about using the factory pattern to choose which specific instrument at run time.

 

Relevant links:

Factory Pattern

Optimizing class loading with the factory pattern

Hardware Emulation using classes

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 4 of 6
(3,185 Views)

Kenny,

 

your Signal Generator class has that "Set Output" method configured as dynamic dispatch and your N5181A class (inherited from Signal Generator) has this as override?

 

Essentially, this is the question from Mark, but i want a clear YES, that is the case or a NO, i have a single instance in N5181A solely from this specific VI.

 

Btw, what says the context help if you hover above the broken wire, alternatively, what says the error list?

The override VI is executable?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 5 of 6
(3,180 Views)

I had many Dynamically dispatched vis, and that was supposed to be one, but I forgot to create the Set Output.vi in my parent class.  I also added the "Force child class to override" flag, which then work as expected.

 

Thank you much.

 

The error was a class conflict (as pictured in my first post).

Kenny

0 Kudos
Message 6 of 6
(3,148 Views)