refactoring : global data - encapsulate variable

This commit is contained in:
haerong22
2022-03-05 15:00:55 +09:00
parent dd1faea4d2
commit ed972eb807
4 changed files with 81 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}