Let’s assume the following scenario:
- List of IoT devices (one model?)
- Each list item has (among other fields) a
- Depending on the value in the
typefield, device may report different values (by number and sometimes type)
And I need to save them in the database (related to reporting device, of course).
So for example:
1(thermometer): only one parameter:
temperature(INT – max. 99 + comma + two decimal places)
2(GPS locator): four parameters:
long(INT – max 999 + comma + 6 decimal places),
height(INT – max 99999, without fractional part),
speed(INT – max 999 + comma + 2 places).
These are of course examples, not an actual case.
I need to model such thing in MVC. Assuming (best of both worlds):
- It should be relatively easy to implement (the project behind is way off time),
- It should be done at least semi-professionally (one day a new project can be created based on this code and we don’t want to rewrite 300 classes from scratch, if that happens).
Can you suggest something around the above?
This is not a “homework” or do-it-for-me question. I don’t need a mature, out-of-the-box solution, only guiding into a correct direction.
I am by no means system architect, I don’t know design patterns very well. So the only thing that came to my mind so far was the simplest concept of two models or tables:
But this seams very redundant (storing the type in each measurement?).
Plus, it only covers data storage itself takes. It does nothing around “configuration” of these parameters (input validation).
For example, how to guarantee that:
- A device with
1will report only one parameter (and only of a specific type)
- A device with
2will report exactly four parameters and always of the specified types
And any other attempt will be rejected.
To resolve this, at the very beginning I was thinking about using separate models. But this seems to be another overkill. As there may be hundreds of types of devices. Which would inflict hundreds of such models.
This question is somewhat similar to this one. Only mine deals with model / data storage and the mentioned one is purely focused on presentation layer (which isn’t a problem for me).
My question is also quite similar to this one. But the mentioned one isn’t answered for three years and I have the feeling that I have come a bit further here.