๋ฅ์จ ๊ธ๋ก๋ฒ ํ๋ซํผ ๊ตฌ์ถ ์ด์ผ๊ธฐ : DB Migration case study (์ํ์ ํ๋ซํผ์ธํ๋ผ์ค Technical Manager, ๋ฅ...Amazon Web Services Korea
๋ฅ์จ ๊ธ๋ก๋ฒ ํ๋ซํผ ๊ตฌ์ถ ์ด์ผ๊ธฐ : DB Migration case study (์ํ์ ํ๋ซํผ์ธํ๋ผ์ค Technical Manager, ๋ฅ...Amazon Web Services Korea
67. ์กฐ๊ฑด๋ก์ง
: ๊ฐ์ฅ๋ ์์๋ฌธ
ํด์ผ ํ ์ผ
public class Employee {
private int type;
private static final int ENGINEER = 0;
๏ฝ
1๋จ๊ณ
private static final int SALESMAN = 1;
private static final int MANAGER = 2; ๏ฝ
public Employee(int type) {
this.type = type; ๏ฝ ๊ฐ์ฒด๊ฐ ์์ฑ๋ ์ดํ Type
}
์ด ๋ณ๊ฒฝ๋ ์ ์๋ ๊ฒฝ์ฐ
Replace Type Code with
public int calculatePayment() {
switch (type) { ๏จ
case ENGINEER:
return monthlySalary; State/Strategy
๋ณ๊ฒฝ๋์ง ์๋ ๊ฒฝ์ฐ
case SALESMAN:
return monthlySalary + commission; ๏ฝ
case MANAGER:
return monthlySalary + bonus; ๏จ Replace Type Code with
default:
throw new RuntimeException("Incorrect Employee"); Subclass
}}
public String getJobTitle() { ๏ฝ 2๋จ๊ณ
switch (type) {
case ENGINEER: ๏ฝ Replace Conditional with
return "Engineer";
case SALESMAN: Class
return "Salesman";
case MANAGER:
return "Manager";
default:
throw new RuntimeException("Incorrect Employee");
}
}}
67 Confidential 12/13/2011