liveBook · Manning

Ready

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

A book-specific state class representing a ticket machine that is ready for customer interaction.

READY is the ticket machine state in which the machine is prepared to accept a customer’s credit card. It is the initial state and handles all four actions, including actions that do not cause a transition. section 13.1.2 section 13.1

READY responds to customer actions as follows:

  • Insert a card: mark it inserted, set validity to unknown, and transition to VALIDATING when no card is present. section 13.1.2

READY as a State object

After refactoring, class READY encapsulates these behaviors instead of sharing a switch statement with every other state. Its action methods return the next State object; ordinary READY actions return this, while card insertion returns states.VALIDATING_state. section 13.1.3

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.

The state diagram shows READY’s position among the ticket machine’s four named states and its transition conditions. section 13.1

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

How deep it goes
Explains READY through action tables, before-pattern branching, and a refactored subclass, stopping short of broader lifecycle concerns.
Examples
Uses credit-card insertion, validation, ticket taking, card removal, and a three-ticket machine to exercise READY behavior.
What it assumes
Uses C++ classes, member functions, references, inheritance, and virtual overrides in the refactored implementation.
What you can do after
Build it from scratch as a C++ State subclass whose actions update machine data and return READY, VALIDATING, or another state.
How it connects
Connects READY to the State Design Pattern, state transitions, 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.