I'm working on a modular project consisting of multiple sensors, each inheriting from an abstract Sensor
class. To configure each sensor, I have started to add a user control panel for each sensor (inherits from UserControl
), which is loaded at runtime and displayed in a panel by the calling application.
But then I realised that to change sensor properties from the control, the Control
class needs to have access to those properties or the sensor has to subscribe to configuration setting changes in the user control. This doesn't feel right, however, the control should be controlling the sensor.
What is the most elegant solution to control my sensors without creating a delegate-hell?
Should I continue on the path of:
class TestSensor : Sensor
{
public UserControl ControlPanel { get; } // returns a TestSensorControl
// ...
}
or should my sensors be created inside my controls:
class TestSensorControl : UserControl
{
private TestSensor _sensor;
public TestSensor Sensor {
get {
return _sensor;
}
}
// ...
}
Sensors are responsible for checking for state changes and communicating it to the calling application by signalling an OnSensorEvent(...)
event.
Alternatively, my base Sensor
class could inherit from UserControl, and my SensorControl can inherit from that instead, eliminating the need for an intermediate control class.