06-10-2020 06:48 AM
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:
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:
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!
06-10-2020 07:39 AM
@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.