Skip to content

Instantly share code, notes, and snippets.

@BobGu
Created May 6, 2016 20:09
Show Gist options
  • Save BobGu/e1b504ab6d2b423fd3cbfaf32485921d to your computer and use it in GitHub Desktop.
Save BobGu/e1b504ab6d2b423fd3cbfaf32485921d to your computer and use it in GitHub Desktop.
public class Order {
State unpaidState;
State paidState;
State shippedState;
State deliveredState;
State state = unpaidState;
public Order() {
unpaidState = new UnpaidState(this);
paidState = new PaidState(this);
shippedState = new ShippedState(this);
deliveredState = new DeliveredState(this);
}
public State getUnpaidState() {
return unpaidState;
}
public State getPaidState() {
return paidState;
}
public State getShippedState() {
return shippedState;
}
public State getDeliveredState() {
return deliveredState;
}
public void verifyCreditCard(String info) {
state.verifyCreditCard(info);
}
public void ship() {
state.ship();
}
public void orderDelivered() {
state.orderDelivered();
}
public void setState(State state) {
this.state = state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment