Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Visitor pattern
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{More citations needed|date=January 2022}} {{short description|Software design pattern}} A '''visitor pattern''' is a [[software design pattern]] that separates the [[algorithm]] from the [[Object (computer science)|object]] structure. Because of this separation, new operations can be added to existing object structures without modifying the structures. It is one way to follow the [[open/closed principle]] in [[object-oriented programming]] and [[software engineering]]. In essence, the visitor allows adding new [[virtual function]]s to a family of [[Class (computer programming)|classes]], without modifying the classes. Instead, a visitor class is created that implements all of the appropriate specializations of the virtual function. The visitor takes the instance reference as input, and implements the goal through [[double dispatch]]. Programming languages with [[Tagged union|sum types]] and [[pattern matching]] obviate many of the benefits of the visitor pattern, as the visitor class is able to both easily branch on the type of the object and generate a compiler error if a new object type is defined which the visitor does not yet handle.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)