My application uses measurement instruments that are connected to the PC. I want to make it possible to use similar instruments from different vendors.
So I defined an interface:
interface IMeasurementInterface
{
void Initialize();
void Close();
}
So far so good. Before a measurement I need to setup the instrument and this means for different instruments very different parameters. So I want to define a method that takes parameters that can have different structures:
interface IMeasurementInterface
{
void Initialize();
void Close();
void Setup(object Parameters);
}
I will then cast the object to whatever I need. Is this the way to go?
You might be better off coming up with an abstract "Parameters" class that is extended by each different instruments parameters... e.g. and then using Generics to ensure that the correct parameters are passed to the correct classes...
public interface IMeasurement<PARAMTYPE> where PARAMTYPE : Parameters
{
void Init();
void Close();
void Setup(PARAMTYPE p);
}
public abstract class Parameters
{
}
And then for each specific Device,
public class DeviceOne : IMeasurement<ParametersForDeviceOne>
{
public void Init() { }
public void Close() { }
public void Setup(ParametersForDeviceOne p) { }
}
public class ParametersForDeviceOne : Parameters
{
}
To me it sound like the Factory pattern might be usefull, especially if your are going to unit test your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With