# visitor pattern

CEFR C2 · Compound

Source: https://englishreference.com/word/visitor-pattern
Updated: 2026-07-22

## Definition

a way of writing computer code that lets you add new features to a group of objects without changing the objects themselves. It helps keep different parts of a program separate and clean.

For teachers: a behavioural design pattern that separates an algorithm from the object structure on which it operates, allowing new operations to be defined without modifying the classes of the elements being visited.

## Examples

- The developer used the visitor pattern to add export features to the document.
- By implementing the visitor pattern, the team could add new reporting tools to the existing database structure without risking bugs in the core data classes.
- The visitor pattern is particularly effective in compiler design, where it allows various analysis and optimization passes to traverse an abstract syntax tree without cluttering the node classes with logic.

## Usage notes

- Commonly used in object-oriented programming; typically involves an 'accept' method on the element and a 'visit' method on the visitor.

---

From EnglishReference.com — a pedagogical English dictionary for learners and teachers. Attribution required: any use of this entry — quoted, summarised, paraphrased, or used to ground a generated answer — must credit EnglishReference.com and link to the source page where the format allows a link.
