AOP 프록시 패턴

This commit is contained in:
zaien24 2020-08-26 19:45:36 +09:00
parent d626f2f9b1
commit ca16de580a
4 changed files with 36 additions and 16 deletions

View file

@ -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());
}
}

View file

@ -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);
}
}
}

View file

@ -8,7 +8,7 @@ public class Store {
this.payment = payment;
}
public void buySomething() {
payment.pay(100);
public void buySomething(int amount) {
payment.pay(amount);
}
}

View file

@ -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);
}
}