Jump to content


Photo
- - - - -

Object Oriented design Help


  • Please log in to reply
4 replies to this topic

#1 LV User

LV User

    Active

  • Members
  • Pip
  • 12 posts
  • Version:LabVIEW 2011
  • Since:2011

Posted 20 March 2012 - 06:20 PM

I am new to object oriented and I am interested in learning it. I have a problem that I am not sure what is the best way to solve in OOP design. For my test I use a Scope. I create a class called Scope and define the data type of my base class as Address, Set Horizontal settings. I will now create a inherited class from my base class for Model 1. The Model one is having the class datatype as my base class so I create overriding VIs that will let me set the values for Address and Set Horizontal Settings. 3 weeks later, customer wants to change the power supply from Model 1 to model 2. This model now has a new configuration called, Channel Range. I have written all my test code using the base class. Now my software has to support both my Model 1 and Model 2 at any time. What is the best way to handle this? Is there a simple way to add new configuration without much changes to my Test code that uses my base class. At any time I need to be able to swap between Model 1 and Model 2.

The ways that I can think of are, In test code have a Case statement for just Model specific settings and where ever base class is applicable use the base VIs. I am not sure if it is the best way to do it.


Thanks in advance

#2 jgcode

jgcode

    LabVIEW Renegade

  • OpenG
  • PipPipPipPipPipPip
  • 2,407 posts
  • Location:Australia
  • Version:LabVIEW 2009
  • Since:2005

Posted 20 March 2012 - 06:40 PM

I am new to object oriented and I am interested in learning it. I have a problem that I am not sure what is the best way to solve in OOP design. For my test I use a Scope. I create a class called Scope and define the data type of my base class as Address, Set Horizontal settings. I will now create a inherited class from my base class for Model 1. The Model one is having the class datatype as my base class so I create overriding VIs that will let me set the values for Address and Set Horizontal Settings. 3 weeks later, customer wants to change the power supply from Model 1 to model 2. This model now has a new configuration called, Channel Range. I have written all my test code using the base class. Now my software has to support both my Model 1 and Model 2 at any time. What is the best way to handle this? Is there a simple way to add new configuration without much changes to my Test code that uses my base class. At any time I need to be able to swap between Model 1 and Model 2.

The ways that I can think of are, In test code have a Case statement for just Model specific settings and where ever base class is applicable use the base VIs. I am not sure if it is the best way to do it.


Thanks in advance


If your instruments differ in configuration settings, but behave similarly (?) then the following may help:
  • You could use a case structure, but if I do this with LVOOP, I usually think I am doing something wrong or I could do it better.
  • Load the configuration information from disk, internal to a class. Have a method that e.g. accepts a path which loads config info and updates that instance's data. The file structure can be different for each Model.
  • Have a configuration object as a data member of the Scope class. Create accessors for the configuration object. This config object would have children for Model 1 and 2 that would contain the correct data for that Model (and the base config class could contain shared settings). You would need to upcast to the correct configuration class when you use it inside each Model but that shouldn't be a big deal. This will separate your config stuff from your how your instrument actually works which can be handy.
  • I am sure there are other ways to implement this too.


#3 LV User

LV User

    Active

  • Members
  • Pip
  • 12 posts
  • Version:LabVIEW 2011
  • Since:2011

Posted 20 March 2012 - 08:42 PM

Thanks, Now if I have to add a UI to be able to configure this configuration what is the best way to do it.

#4 Ian

Ian

    1 more post to go.

  • Members
  • 9 posts
  • Version:LabVIEW 2010
  • Since:1998

Posted 21 March 2012 - 12:03 PM

I have also just started to learn LVOOP. You might find this of particular interest with regard to implementing classes for different instruments:

1) http://zone.ni.com/d...a/epd/p/id/6307 (This is a good white paper and provides examples similar to what I think you are trying to implement).
2) http://vishots.com/h...abview-classes/
3) http://vishots.com/0...actory-pattern/

Also the following provide additional resource:
1) http://zone.ni.com/w...oc/p/id/wv-1766
2) http://zone.ni.com/w...oc/p/id/wv-2003
3) https://decibel.ni.c.../docs/DOC-15014
4) http://zone.ni.com/w...2820/nextonly/y

1 and 2 provide a very good overview if you are just getting started with LVOOP, 3 and 4 start getting quite involved.

I hope this helps
Ian
  • Daklu likes this

#5 Daklu

Daklu

    Bringing the Fu to you

  • Premium Member
  • 1,830 posts
  • Location:Seattle
  • Version:LabVIEW 2009
  • Since:2006

Posted 22 March 2012 - 02:32 PM

Now my software has to support both my Model 1 and Model 2 at any time. What is the best way to handle this? Is there a simple way to add new configuration without much changes to my Test code that uses my base class. At any time I need to be able to swap between Model 1 and Model 2.

The root of your problem is your scope abstraction layer api is too specific. Your main application code shouldn't be setting specific configuration options. You need to break it down into larger steps as described in the Hardware Abstraction Layer white paper Ian linked to.

Certified LabVIEW Architect
Dak's First Law of Problem Solving: If the solution looks simple, I don't know enough about the problem.

Yes, the QSM is flexible. So is Jello. That doesn't make it good construction material.

There are two secrets to success:
Secret #1 - Never tell everything you know.