Relationships

[Previous] [Next]

To obtain the dynamically changing behavior desired, a client must reference a ConcreteState object that in turn maintains a reference to a CentralStateManager object. Changes submitted by the client that affect state are forwarded to the CentralStateManager object.

The CentralStateManager object serves as the single central repository for state storage. It contains references to all available State objects. It performs the correct state transition behavior by returning a reference to the appropriate State object based on changes to its internal state.

When a client invokes behavior on a State object after a state change, this invocation will either be handled by the actual object or will be delegated to a different state object determined by the CentralStateManager. Figure 12-2 illustrates an object structure in which a client created a ConcreteStateA object. As a result, the ConcreteStateA object creates a CentralStateManager object that in turn creates all other State objects available. This diagram shows that without any state changes, invocations are handled internally by the original State object (ConcreteStateA) created by the client. Figure 12-3 illustrates the process that takes place when state changes that are sensitive to the CentralStateManager object occur. Those changes have caused the CentralStateManager object to return a reference to the ConcreteStateD object. Invocations to the ConcreteStateA object will now be delegated to the ConcreteStateD object until further changes to state occur that result in a state transition by the CentralStateManager.

click to view at full size.

Figure 12-2. Object structure of an initial state A determined by the ConcreteStateA object. Because no state changes have occurred yet, the CentralState-Manager object refers the ConcreteStateA object back to itself.

click to view at full size.

Figure 12-3. Object structure of a State object that initially started out in state A (determined by the client's choice to create a ConcreteStateA object) that has been affected by state changes causing the CentralStateManager object to return a reference to ConcreteStateD. Client invocations on the ConcreteStateA object will be delegated to ConcreteStateD.



Microsoft Visual Basic Design Patterns
Microsoft Visual Basic Design Patterns (Microsoft Professional Series)
ISBN: B00006L567
EAN: N/A
Year: 2000
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net