Waiting state pattern

When modeling object lifecycles, there are often situations where the process cannot continue until some separate, but related, activity completes. This can be modeled by using a waiting pattern. In this pattern, a state is used to indicate that it is waiting for something to occur.

The following figure shows this pattern.

Figure 1. Example of the waiting state pattern
FTMWaitingStatePattern.jpg

The example shows a situation where a payment instruction is received and forwarded to a payment gateway. The payment object is placed in the S_WaitingForAck state. At some later stage, an acknowledgment is returned from the gateway and some other component raises the E_PaymentAcknowledged event. This event causes the FSM to transition to completion.

By convention, the name of a state in this pattern should indicate that the object is waiting for something to happen.