So, I've built a data logger device communicating via Modbus protocol. Works great, firmware is my field of somewhat expertise. I've been crash coursing C# for the past couple weeks, trying to get my head wrapped around object-oriented coding, in order to build myself an app to view the sensor data from my device as a continuous plotting chart. The device can broadcast sensor data from 8 different channels.
Only took me a weekend to get a demo up and running, but not utilizing any sort of OOP-like code, since I don't really know what the fuck I'm doing with OOP yet.. The code looked like a trad C garage-class code piece of crap.
I've been trying to follow the MVVM model, I have the different functional parts broken up:
- has everything I need to extract the incoming sensor data. I simply pass it a baud rate and com port, run the connect function, and the engine updates the ChannelModel for 8 channels as the data logger sends it. We trigger an event to notify new data is available, so the ChannelModel is updated on every trigger.
- Uses the data from ChannelModel to plot a chart
- Contains 8 channel labels (strings) and 8 channel present values (double). Contains an event to let the ChartEngine know new data is available, and to plot it.
- Simply a class with two properties, time and present value. This is the package I send the current channel data to the ChartEngine.
- Basically just initializes and starts the CaptureEngine and ChartEngine
- Contains properties of visible data, (channel_1_label_vm, channel_2_label_vm... etc). Also contains code for the visual elements such as buttons, textboxes, etc.
I'm wondering.. is making my ChannelModel a static class, so that all classes can see the channel data it contains, a good move? Because creating a non-static instance doesn't seem to work.. the other classes won't see it.
Now this all works just fine, but the whole static ChannelModel class seems like I'm misbehaving/not utilizing C# like I should be..
My question I'm hoping to get some insight into is, in what situations would you use a static class? Is it common for static classes to be used incorrectly/abused?