VALIDATING is the ticket machine state reached after a customer inserts a credit card. The machine marks the card as inserted, sets its validity to UNKNOWN, and checks whether validation succeeds. A valid card leads to TICKET_SOLD; an invalid card returns the machine to READY. section 13.1.2 section 13.1
The state governs each available machine action:
- check_validity() randomly resolves UNKNOWN to YES or NO; YES permits ticket collection, while NO rejects the card and returns to READY. section 13.1.2
- take_ticket() reports that validation is still in progress when validity remains UNKNOWN; a validated card permits the customer to take the ticket. section 13.1.2
- remove_credit_card() clears the card and validity information and transitions to READY, including when the customer cancels before validation finishes. section 13.1.2
- In a State Design Pattern implementation, a VALIDATING object encapsulates these actions and returns either itself or the next state instead of sharing one large action switch. section 13.1.3
A validation flow
Starting at READY, the customer inserts a card and reaches VALIDATING with card_inserted=true and card_validity=unknown. Checking validity may produce “Your credit card is validated. Take your ticket.” and move to TICKET_SOLD, or reject the card and return to READY. Removing the card before the check also returns to READY with unknown validity. section 13.1
Figure 13.1 A UML state diagram showing the four states and the state transitions of an automatic ticket machine. The machine keeps track of the number of tickets it has, whether there is a credit card inserted, and the validity status of the card. Customer and machine actions (numbered; e.g., 1: insert card) or certain conditions (in square brackets; e.g., [card invalid]) can cause transitions from one state to another. This figure only shows the actions that cause transitions.
Use the state diagram to trace how card insertion, validation results, ticket collection, and card removal move the machine into and out of VALIDATING. section 13.1
