liveBook · Manning

Ticket_sold

As explained in Object-Oriented Software Design in C++

A named ticket-machine state in which the machine has sold a ticket and the customer can take it.

ticket_sold names the ticket machine state reached after a credit card is validated and a ticket is sold. The customer can now take the ticket. section 13.1

While ticket_sold is active, customer actions produce state-specific behavior:

  • Inserting a card or checking validity tells the customer to take the ticket already bought. section 13.1.2
  • Taking the ticket removes the card, displays an enjoyment message, decrements the ticket count, and transitions to READY or SOLD_OUT. section 13.1.2 section 13.1.3
  • Removing the card first is rejected with a request to take the ticket. section 13.1.2

A successful sale

The machine moves from READY to VALIDATING when a card is inserted, then to ticket_sold after validation. Taking the ticket changes the count from three to two and returns the machine to READY. 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 ticket_sold's incoming and outgoing transitions alongside the other ticket-machine states. section 13.1

How Object-Oriented Software Design in C++ covers it

How deep it goes
Defines the state and details each action's behavior, then encapsulates those actions in a dedicated State subclass.
Examples
Demonstrates successful validation, ticket collection, card removal, count decrementing, and transition to READY or SOLD_OUT.
What it assumes
Assumes familiarity with credit-card validation and ticket-machine actions while introducing named states and their transitions concretely.
What you can do after
Evaluate/understand how a named state governs actions and determines the next state after ticket collection.
How it connects
Connects ticket_sold to state transitions, the State Design Pattern, polymorphism, and encapsulation.

This explainer was generated by Manning's knowledge graph from the text of Object-Oriented Software Design in C++. The section links point to the parts of the book it draws on.