Here is my problem: I want to read input from different HID devices such as a gamepad, racing well, joystick, etc. Pretty much any game controller. The issue is that they all have different inputs.
The gamepad has buttons, switches and sticks while the racing well might have a gear stick. I managed to abstract all these different components into just 3 so instead of having a base class with all possible combinations:
abstract class Device
{
public Buttons Buttons;
public Axes Axes;
public Switches Switches;
public GearSticks GearSticks;
//many more
}
I can now have:
abstract class Device
{
public Buttons Buttons; //on or off
public Axes Axes; //range [-100%:100%]
public Switches Switches; //multiple states
}
At first I was happy with this since it seemed to cover all possible types of input and so my class can stay closed while being open to extension via all the concrete implementations since everything can be abstracted to just 3 types of input.
BUT then I though to myself what if I'm just delaying the inevitable? What if one day I will have to add another field to my Device
class? It does not support something like a trackball!
Is there a way I can future proof this class? The way I see it I would end up with something like this:
public Device1 : Device
{
//buttons
//trackball
}
public Device2 : Device
{
//Switch
//Axis
}
public Device3 : Device
{
//trackball
//switch
}
And I would have to keep adding properties to my base class every time there is something new to implement.