public interface Payment {
void pay(int amount);
}
public class Cash implements Payment {
@Override
public void pay(int amount) {
System.out.println(amount + " 현금 결제");
}
}
public class CashPerf implements Payment{
Payment cash = new Cash();
@Override
public void pay(int amount) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
if(amount > 100) {
System.out.println(amount + " 신용 카드");
} else {
cash.pay(amount);
}
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
}
}
public class Store {
Payment payment;
public Store(Payment payment) {
this.payment = payment;
}
public void buySomething(int amount) {
payment.pay(amount);
}
}
public class StoreTest {
public void testPay() {
Payment cashPerf = new CashPerf();
Store store = new Store(cashPerf);
store.buySomething(100);
}
}
'DEV > Spring' 카테고리의 다른 글
JPA 설정 (0) | 2020.11.01 |
---|---|
VS Code에서 Gradle 및 Java 빌드가 안될경우 (0) | 2020.10.31 |
VSCode로 Spring Boot 시작하기 (0) | 2020.09.14 |