38. 다음의 Car 클래스의 speedUp 메소드는 NOT_MOVING,MOVING, FAILED 등에 따라서 상이한 동작을 switch문으로 구현하고 있다. 이와 같은 상황에서 적용하기에가장 적합한 리팩토링(refactoring) 기법은?
class Car {
private int _type;
public static final int NOT_MOVING = 0;
public static final int MOVING = 1;
public static final int FAILED = 2;
public Car() { _type = NOT_MOVING; }
public void speedUp() {
switch ( _type ) {
case NOT_MOVING: ... break;
case MOVING: ... break;
case FAILED: ... break;
default: ... break;
}
}
}
- 1replace parameter with method

- 2replace type code with state/strategy

- 3introduce parameter object

- 4remove control flag
