Design Architecture/Refactoring
Replace Data Value with Object
lipnus
2022. 4. 20. 08:38
반응형
데이터의 기능이 복잡해지면 객체로 만든다.
Before
public class ReplaceDataValueWithObject_before {
static public class Order {
private String customer;
public Order(String customer) {
this.customer = customer;
}
public String getCustomer() {
return this.customer;
}
public void setCustomer(String arg) {
this.customer = arg;
}
}
public static void main(String[] args) {
Order order = new Order("david");
System.out.println(order.getCustomer());
}
}
After
public class ReplaceDataValueWithObject_before {
static public class Order {
private Customer customer;
public Order(String customer) {
this.customer = new Customer(customer);
}
public String getCustomer() {
return this.customer.toString();
}
// public void setCustomer(String arg) {
// this.customer = arg;
// }
}
static class Customer {
String value;
Customer(String value) {
this.value = value;
}
public String toString() {
return value;
}
}
public static void main(String[] args) {
Order order = new Order("david");
System.out.println(order.getCustomer());
}
}
반응형