by Tarean · 9y ago · 0 comments
Temperature temp = Temperature.fromCelsius(13);
...
System.out.println(temp.celsius);
would have to be changed to System.out.println(temp.getCelsius());
when the internal representation is changed. class Temperature {
public final double celcius, kelvins;
Temperature(int celcius, int kelvins) {
this.celcius = celcius;
this.kelvins = kelvins;
}
public static Temperature fromCelcius(int c) {
return new Celcius(c, c - 273.15);
}
}
What's wrong with that approach, and how would you do it?Just have one in Kelvin that can't go below zero, and have getters and setters that translate to C/F when specified.
I'm open to the idea that setters do have a use case, but I'm not seeing one here.