Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2009ACS - 3913 Ron McFadyen1 The context maintains an instance of a concrete state subclass State Pattern Each subclass (concrete state) implements.

Similar presentations


Presentation on theme: "Fall 2009ACS - 3913 Ron McFadyen1 The context maintains an instance of a concrete state subclass State Pattern Each subclass (concrete state) implements."— Presentation transcript:

1 Fall 2009ACS - 3913 Ron McFadyen1 The context maintains an instance of a concrete state subclass State Pattern Each subclass (concrete state) implements the behaviour associated with a state of the context. The state provides an interface for encapsulating behaviour associated with a particular state. Generic UML class diagram: Context «Interface» State ConcreteStateAConcreteStateB State concrete state state context

2 Fall 2009ACS - 3913 Ron McFadyen2 An Account behaves differently depending on its balance. The difference in behavior is delegated to State objects called RedState, SilverState and GoldState. These states represent overdrawn accounts, starter accounts, and accounts in good standing. State Pattern Consider dofactory web site

3 Fall 2009ACS - 3913 Ron McFadyen3 Process Sale Use Case Recall We can construct a State Diagram showing states for this use case

4 Fall 2009ACS - 3913 Ron McFadyen4 Waiting For Sale; Entering Items; Waiting For Payment are System states that arise in the Process Sale use case. Figure 29.2 Transitions are system events … the diagram clearly shows when events, such as makeNewSale, are legal.

5 Fall 2009ACS - 3913 Ron McFadyen5 Register knows its current state State Pattern The state provides an interface for encapsulating behaviour associated with a particular state. These system operations need to execute according to the state the system is in. Consider Register makeNewSale() enterItem(…) endSale() makePayment(…) WaitingForSaleStateEntering Items State State concrete state state context «Interface» State Consider the sample code discussed in class

6 Fall 2009ACS - 3913 Ron McFadyen6 This statechart diagram depicts the states that a persistent object can be in and the valid transitions from state to state. Examine the Figure on “applying the state pattern” State Pattern Consider the text and the section “Transactional States and the State Pattern”


Download ppt "Fall 2009ACS - 3913 Ron McFadyen1 The context maintains an instance of a concrete state subclass State Pattern Each subclass (concrete state) implements."

Similar presentations


Ads by Google