mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 07:15:49 +00:00
AOP 프록시 패턴
This commit is contained in:
parent
d626f2f9b1
commit
ca16de580a
4 changed files with 36 additions and 16 deletions
|
@ -0,0 +1,18 @@
|
||||||
|
package org.springframework.samples.petclinic.proxy;
|
||||||
|
|
||||||
|
import org.springframework.util.StopWatch;
|
||||||
|
|
||||||
|
public class CashPerf implements Payment {
|
||||||
|
Payment cash = new Cash();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pay(int amount) {
|
||||||
|
StopWatch stopWatch = new StopWatch();
|
||||||
|
stopWatch.start();
|
||||||
|
|
||||||
|
cash.pay(amount);
|
||||||
|
|
||||||
|
stopWatch.stop();
|
||||||
|
System.out.println(stopWatch.prettyPrint());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.proxy;
|
|
||||||
|
|
||||||
public class CreditCard implements Payment {
|
|
||||||
Payment cash = new Cash();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pay(int amount) {
|
|
||||||
if (amount > 100) {
|
|
||||||
System.out.println(amount + " 신용 카드");
|
|
||||||
} else {
|
|
||||||
cash.pay(amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,7 +8,7 @@ public class Store {
|
||||||
this.payment = payment;
|
this.payment = payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buySomething() {
|
public void buySomething(int amount) {
|
||||||
payment.pay(100);
|
payment.pay(amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.springframework.samples.petclinic.proxy;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class StoreTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPay() {
|
||||||
|
Payment cashPerf = new CashPerf();
|
||||||
|
Store store = new Store(cashPerf);
|
||||||
|
store.buySomething(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue