Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Visitor pattern
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
==Overview== The Visitor<ref name="GoF">{{Cite book |last=Gamma |first=Erich |author-link=Erich Gamma |url=https://archive.org/details/designpatternsel00gamm/page/331 |title=Design Patterns: Elements of Reusable Object-Oriented Software |last2=Helm |first2=Richard |author-link2=Richard Helm |last3=Johnson |first3=Ralph |author-link3=Ralph Johnson (computer scientist) |last4=Vlissides |first4=John |author-link4=John Vlissides |publisher=Addison Wesley |year=1994 |isbn=0-201-63361-2 |pages=[https://archive.org/details/designpatternsel00gamm/page/331 331ff] |url-access=registration}}</ref> design pattern is one of the twenty-three well-known ''[[Design Patterns|Gang of Four design patterns]]'' that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse. === Problems, the Visitor design pattern can solve === * It should be possible to define a new operation for (some) classes of an object structure without changing the classes. When new operations are needed frequently and the object structure consists of many unrelated classes, it's inflexible to add new subclasses each time a new operation is required because "[..] distributing all these operations across the various node classes leads to a system that's hard to understand, maintain, and change."<ref name="GoF" /> === Solution, the Visitor design pattern describes === * Define a separate (visitor) object that implements an operation to be performed on elements of an object structure. * Clients traverse the object structure and call a ''dispatching operation accept (visitor)'' on an element β that "dispatches" (delegates) the request to the "accepted visitor object". The visitor object then performs the operation on the element ("visits the element"). This makes it possible to create new operations independently from the classes of an object structure by adding new visitor objects. See also the UML class and sequence diagram below.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Visitor pattern
(section)
Add topic