LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with choosing best class hierarchy for use in multiple programs

Hello, I have a question regarding the structure of my class hierarchy. I'm just starting out with OOP, so please excuse me if this should be obvious.

 

I have a source meter and an oscilloscope (and possibly others in the future) to measure voltage and current of a DUT. I would like to implement classes to dynamically switch between these devices by, for example, a drop-down list. Now, I made a parent class called Device and two child classes, one for each device. Then using the VI from overide function, I create all the functions (for now Initialize, Measure and Shutdown) for both devices. So far so good, the program is working well. Here is the class hierarchy, that I have now:

Picture1.png

 

But now I want to make a new program that has different functionality (i.e. the code for the Initialize, Measure and Shutdown VIs is different) from the previous program, but still uses the same devices to measure. I supposed I should use the same classes for both programs (it would be silly to remake the class hierarchy every time), but I don't see how the structure should be. I was thinking about this:

Picture2.png

But then I still have to manually create, for each new program, the three child classes, change inheritance, make VI from overide for each VI etc... It seems very cumbersome. Is there a better structure? Or a better way to deal with this?

I would like to learn about this stuff, but it hasn't fully 'clicked' in my mind yet. Any help would be greatly appreciated!

0 Kudos
Message 1 of 2
(1,978 Views)

@Basjong53 wrote:

But now I want to make a new program that has different functionality (i.e. the code for the Initialize, Measure and Shutdown VIs is different) from the previous program, but still uses the same devices to measure. I supposed I should use the same classes for both programs (it would be silly to remake the class hierarchy every time), but I don't see how the structure should be. I was thinking about this:


Personally, I have not found a good way to have a "Device" class yet that goes beyond "Initialize" and "Close".  Even then, my Initialize method will be based on reading a configuration, XML, or JSON file.  What I do is have a base class for each type of instrument and have my applications call those.  The more specific implementations are then handled in child classes below those.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 2
(1,962 Views)