liveBook · Manning

Event

As explained in Software Design for Python Programmers

An event is an occurrence defined by an object's behavior that can cause the object to transition from one state to another.

An event is an occurrence defined by an object's behavior that can move the object from one state to another. In a UML state diagram, states appear as boxes, transitions as arrows, and event labels identify the behavior causing each transition. section 4.4

A car changing state

A Car begins in the parked state. Starting the engine is an event that changes it to idling; accelerating then changes it to heading north. The object's speed and heading instance variables characterize its runtime state. section 4.4

Use events to reason about behavior and design:

  • Connect each event to the behavior that produces it, usually an object's method. section 4.4
  • Map the event to the state transition it causes, including decision branches, merges, forks, and joins when behavior is conditional. section 4.4
  • Use published Event objects to notify multiple observers when a subject changes, allowing log, table, graph, and fan-club reports to respond independently. section 12.1.3
  • Distinguish domain events from Python's threading.Event, which coordinates threads by signaling that meter setting has started. section 16.3.1

A baseball Event

EventMaker produces Event objects for each hit. BaseballReporter stores the current event and notifies attached observers with the player's name. LogReport interprets the hit, TableReport updates per-player counts, GraphReport accumulates hit categories, and FanClubReport responds to a selected player. section 12.1.3

Figure 4.15 A UML state diagram that shows the state changes of a Car object during run time. Each box represents a state, and each arrow represents a transition from one state to another. Each transition is labeled with the behavior (event) that causes the transition. Such a diagram allows us to visualize what happens to a particular object during run time and helps to ensure that we designed the class with the correct instance variables and methods.
A screenshot of a phone

Description automatically generated

Visualizes a Car object's states, transitions, and behavior-labeled events at run time. section 4.4

How Software Design for Python Programmers covers it

How deep it goes
Defines events through UML transitions and Python examples, but stops short of formal event-system internals.
Examples
Uses Car movement, Student course enrollment, baseball hits, and a thread-synchronization signal as concrete event examples.
What it assumes
Assumes basic objects, instance variables, methods, and classes while teaching runtime states and transitions through examples.
What you can do after
Evaluate object design by tracing events, behaviors, states, transitions, and dependent-object notifications.
How it connects
Connects events to object behavior, state transitions, UML state diagrams, the Observer pattern, and multithreading.

Also explained in

Compare how 18 books explain event →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Design for Python Programmers. The section links point to the parts of the book it draws on.