refactoring : global data - encapsulate variable
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package com.example.refactoring._05_global_data._00_before;
|
||||
|
||||
public class Home {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Thermostats.targetTemperature);
|
||||
Thermostats.targetTemperature = -1111600;
|
||||
Thermostats.fahrenheit = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.refactoring._05_global_data._00_before;
|
||||
|
||||
public class Thermostats {
|
||||
|
||||
public static Integer targetTemperature = 70;
|
||||
|
||||
public static Boolean heating = true;
|
||||
|
||||
public static Boolean cooling = false;
|
||||
|
||||
public static Boolean fahrenheit = true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.example.refactoring._05_global_data._17_encapsulate_variable;
|
||||
|
||||
public class Home {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Thermostats.getTargetTemperature());
|
||||
Thermostats.setTargetTemperature(68);
|
||||
Thermostats.setFahrenheit(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.example.refactoring._05_global_data._17_encapsulate_variable;
|
||||
|
||||
public class Thermostats {
|
||||
|
||||
private static Integer targetTemperature = 70;
|
||||
|
||||
private static Boolean heating = true;
|
||||
|
||||
private static Boolean cooling = false;
|
||||
|
||||
private static Boolean fahrenheit = true;
|
||||
|
||||
|
||||
public static Integer getTargetTemperature() {
|
||||
return targetTemperature;
|
||||
}
|
||||
|
||||
public static void setTargetTemperature(Integer targetTemperature) {
|
||||
// TODO validation ....
|
||||
Thermostats.targetTemperature = targetTemperature;
|
||||
}
|
||||
|
||||
public static Boolean getHeating() {
|
||||
return heating;
|
||||
}
|
||||
|
||||
public static void setHeating(Boolean heating) {
|
||||
Thermostats.heating = heating;
|
||||
}
|
||||
|
||||
public static Boolean getCooling() {
|
||||
return cooling;
|
||||
}
|
||||
|
||||
public static void setCooling(Boolean cooling) {
|
||||
Thermostats.cooling = cooling;
|
||||
}
|
||||
|
||||
public static Boolean getFahrenheit() {
|
||||
return fahrenheit;
|
||||
}
|
||||
|
||||
public static void setFahrenheit(Boolean fahrenheit) {
|
||||
Thermostats.fahrenheit = fahrenheit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user