Created
January 30, 2019 14:25
-
-
Save nschlimm/94ce85f9cc553b2ae9546031162504b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shopping basket with state pattern | |
public static class ShoppingBasket { | |
private String orderNo; | |
private List<String> articleNumbers = new ArrayList<>(); | |
private UpdateState state = UpdateState.UPDATEABLE; | |
public void add(String articleNumber) { | |
articleNumbers.add(state.set(articleNumber)); | |
} | |
public String getOrderNo() { | |
return orderNo; | |
} | |
public void setOrderNo(String orderNo) { | |
this.orderNo = state.set(orderNo); | |
} | |
public void order() { | |
// some ordering logic and if succeeded, change state | |
state = UpdateState.READONLY; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment