Visitor design pattern

E679870

The Visitor design pattern is a behavioral software design pattern that lets you separate algorithms from the object structures they operate on, enabling new operations to be added without modifying the existing classes.

All labels observed (5)

How this entity was disambiguated

Statements (53)

Predicate Object
instanceOf behavioral design pattern
software design pattern
applicableWhen classes defining the object structure rarely change
many unrelated operations need to be performed on objects in a structure
object structure is relatively stable
belongsTo Gang of Four design patterns
benefit can simplify maintenance of complex operations
facilitates adding cross-cutting operations
improves separation of concerns between data structures and operations
keeps related operations together in visitor classes
supports accumulation of state during traversal
commonUseCase code analysis tools
compilers and abstract syntax tree processing
document object model traversal
operations on hierarchical data structures
coreMechanism double dispatch
definesCollaborationBetween Element
ObjectStructure
Visitor
describedIn Design Patterns: Elements of Reusable Object-Oriented Software
drawback adding a new element class requires changes to all existing visitors
can break encapsulation by exposing element internals to visitors
increases coupling between visitors and element classes
enables adding new operations by creating new visitor classes
hasAlias Visitor
hasCategory behavioral pattern
introducedBy Erich Gamma
John Vlissides
Ralph Johnson
Richard Helm
keyMethod accept()
visit()
oftenUsedWith composite pattern
interpreter pattern
linked to: Interpreter

iterator pattern
primaryIntent enable adding new operations without modifying existing classes
separate algorithms from object structures
relatedConcept double dispatch
open/closed principle
separation of concerns
requires modifying visitor interface when adding new element types
supports open/closed principle
supportsLanguageFeature emulation of multiple dispatch in single-dispatch languages
tradeOff easy to add new operations but hard to add new element classes
typicalLanguageContext object-oriented programming
typicalStructureElement ConcreteElement class
ConcreteVisitor class
linked to: ConcreteVisitor

Element interface
ObjectStructure class
Visitor interface
usedFor defining new operations on object structures
performing operations on elements of an object structure
traversing complex object structures

How these facts were elicited

Referenced by (12)

Full triples — surface form annotated when it differs from this entity's canonical label.

Composite relatedTo Visitor design pattern
Composite oftenUsedWith Visitor design pattern
Interpreter relatedTo Visitor pattern
linked to: Visitor design pattern
Visitor alsoKnownAs Visitor pattern
linked to: Visitor design pattern
Iterator pattern relatedTo Visitor pattern
linked to: Visitor design pattern
ConcreteVisitor belongsToPattern Visitor pattern
linked to: Visitor design pattern
ConcreteVisitor definedBy Gamma et al. (Gang of Four) Visitor pattern description
linked to: Visitor design pattern
ConcreteElement partOf Visitor design pattern
ConcreteElement relatedConcept Double dispatch
linked to: Visitor design pattern
ConcreteElement patternContext Gang of Four Visitor pattern
linked to: Visitor design pattern
Composite pattern relatedTo Visitor pattern
linked to: Visitor design pattern
Gang of Four design pattern hasExample Visitor pattern
linked to: Visitor design pattern