Getting around to the thinking of OOP. Please correct me if this is horrible way of structuring code.
Imagine there is a class Thermometer
. Inside the class I have got 3 structs config
Limit
Measurements
. At different times during the day the code will keep a list of classes Thermometer
and take measurements. Check if they are within a certain limits and save to a json.
Now imagine I've got a json containing the limits as such:
{
"Thermometer1" : {
"sevenPM":
{
"Min" : 10,
"Max" : 20
},
"twelvePM":
{
"Min" : 15,
"Max" : 25
},
"threePM":
{
"Min" : 30,
"Max" : 35
}
},
"Thermometer2" : {
"sevenPM":
{
"Min" : 30,
"Max" : 40
},
"twelvePM":
{
"Min" : 45,
"Max" : 60
},
"threePM":
{
"Min" : 22,
"Max" : 30
}
}
}
Here is the class:
Class Thermometer
{
Thermometer()
{
Limits _limits = new Limits();
CONFIG _config = new CONFIG();
Measurements _measurements = new Measurements();
}
Method1()
{
//does calculations
}
Method2()
{
//does calculation
}
}
The structs:
struct CONFIG
{
bool inShadeorInSun;
string Thermometer_Model;
string Location;
}
struct Limits
{
struct sevenPM
{
double Min;
double Max;
}
struct twelvePM
{
double Min;
double Max;
}
struct threePM
{
double Min;
double Max;
}
}
struct Measurements
{
double sevenPM;
double twelvePM;
double threePM;
}
When I write the list of classes Thermometer to a json i will get an entry for each thermometer. Each thermometer will have config, limits and measurements header inside it. This is to record the config of course, the limit that was set at the time of the recording and the measurements.
On app startup I want the application to read the Limits json and when adding a new thermometer I can simply say: "Import Thermometer2 Limits" and do something like this:
string json = File.ReadAllText("Limits.json");
dynamic read_limits = JsonConvert.DeserializeObject<dynamic>(json);
read_limits = jsonobject["Thermometer2"];
Thermometer _thermometer2 = new Thermometer();
_thermometer2._limits = read_limits;
I think I have got everything right in terms of OOP?? but I am also having issues deserialising the json into the struct.
the last line _thermometer2._limits = read_limits;
does not work
Is this a good handling of OOP?