Skip to content

Instantly share code, notes, and snippets.

@itssomething
Last active March 11, 2019 16:59
Show Gist options
  • Save itssomething/003bcf3baba22e6ae33d2cda680c441c to your computer and use it in GitHub Desktop.
Save itssomething/003bcf3baba22e6ae33d2cda680c441c to your computer and use it in GitHub Desktop.
Order.java
public class Order {
private Cart cart;
// auto gen constructor + getter setter
}
BuyApprove.java
public class BuyApprove{
protected BuyApprove nextApprove;
public void approveOrder(Order order){
sout("log de biet la dang o day");
if(this.canApprove(order.cart.getTotalMoney())){
this.doApprove(order);
}
}
public void setNext(Buyapprove buyApprove){
this.nextApprove = buyApprove;
}
protected abstract boolean canApprove(float totalMoneyOfCart);
protected abstract void doApproving(BuyApprove nextApprove);
}
MailApprove.java
public class MailApprove extends BuyApprove{
@Override
protected boolean canApprove(float totalMoney){
return totalMoney <= 10000000;
}
@Override
protected void doApproving(Order order){
return totalMoney <= 10000000;
System.out.println("Buy request approved for " + order.cart.getTotalMoney() + "by EMAIL");
}
}
PhoneApprove.java
public class PhoneApprove extends PhoneApprove{
@Override
protected boolean canApprove(float totalMoney){
return totalMoney <= 50000000;
}
@Override
protected void doApproving(Order order){
return totalMoney <= 50000000;
System.out.println("Buy request approved for " + order.cart.getTotalMoney() + "by PHONE");
}
}
BuyRequestWorkFlow.java
public class BuyRequestWorkFlow {
public static BuyApprove getApprover() {
BuyApprove mailapprove = new MailApprove();
BuyApprove phoneapprove = new PhoneApprove();
mailapprove.setNext(phoneapprove);
return mailapprove;
}
}
App.java
public class App {
public static void main(String[] args) {
BuyRequestWorkFlow.getApprover().approveOrder(new Order(// khởi tạo 1 order ở đây));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment