mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 23:05:50 +00:00
AOP1
This commit is contained in:
parent
a5a1dea50f
commit
d626f2f9b1
4 changed files with 45 additions and 0 deletions
|
@ -0,0 +1,11 @@
|
|||
package org.springframework.samples.petclinic.proxy;
|
||||
|
||||
public class Cash implements Payment {
|
||||
|
||||
@Override
|
||||
public void pay(int amount) {
|
||||
System.out.println(amount + "현금 결재" );
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package org.springframework.samples.petclinic.proxy;
|
||||
|
||||
public interface Payment {
|
||||
|
||||
void pay(int amount);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.springframework.samples.petclinic.proxy;
|
||||
|
||||
public class Store {
|
||||
|
||||
Payment payment;
|
||||
|
||||
public Store(Payment payment) {
|
||||
this.payment = payment;
|
||||
}
|
||||
|
||||
public void buySomething() {
|
||||
payment.pay(100);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue