liveBook · Manning

Visitor interface

As explained in Software Design for Python Programmers

A visitor interface is an interface declaring operations for visiting each supported element type in an object structure.

A visitor interface declares one operation for each supported element type in an object structure. Implementing visitors place distinct algorithms behind the same interface, while the element classes retain the data structure. section 11.2.3

Report visitors

ScoresReportVisitor, ActivitiesReportVisitor, and WinningsReportVisitor implement the interface and produce different reports by traversing the same intramural tree.

How Software Design for Python Programmers covers it

How deep it goes
Defines abstract visit methods and explains accept-based runtime dispatch, but defers broader implementation trade-offs.
Examples
Uses intramural, sport, game, and hall nodes with scores, activities, and winnings report visitors.
What it assumes
Assumes interfaces, abstract methods, inheritance, and polymorphism while demonstrating the Node and Visitor contracts.
What you can do after
Apply it via polymorphic accept calls to add report algorithms without modifying the data collection.
How it connects
Connects Visitor, Node interface, object structure, polymorphism, and report-generation algorithms.

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.