Last active
August 21, 2023 17:49
-
-
Save mcsee/817257ca2966c8f2381dcf9887dfa1a4 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
public abstract class OrderState { } | |
public final class OrderStatePending extends OrderState { } | |
// This is a polymorphic hierarchy with different behavior | |
// An enum is not enough to model state | |
public final class Order { | |
public Order(LinkedList<int> items) { | |
LinkedList<int> items = items; | |
OrderState state = new OrderStatePending(); | |
} | |
public function changeStatus(OrderState newState) { | |
OrderState state = newState; | |
} | |
public function confirm() { | |
state.Confirm(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment