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!
== Structure == === UML class and sequence diagram === [[File:w3sDesign Visitor Design Pattern UML.jpg|frame|none|A sample [[Unified Modeling Language|UML]] class diagram and [[sequence diagram]] for the Visitor design pattern.<ref>{{Cite web |title=The Visitor design pattern - Structure and Collaboration |url=http://w3sdesign.com/?gr=b11&ugr=struct |url-status=dead |access-date=2017-08-12 |website=w3sDesign.com}}</ref>]] In the [[Unified Modeling Language|UML]] [[class diagram]] above, the <code>ElementA</code> class doesn't implement a new operation directly. Instead, <code>ElementA</code> implements a ''dispatching operation'' <code>accept(visitor)</code> that "dispatches" (delegates) a request to the "accepted visitor object" (<code>visitor.visitElementA(this)</code>). The <code>Visitor1</code> class implements the operation (<code>visitElementA(e:ElementA)</code>). <br> <code>ElementB</code> then implements <code>accept(visitor)</code> by dispatching to <code>visitor.visitElementB(this)</code>. The <code>Visitor1</code> class implements the operation (<code>visitElementB(e:ElementB)</code>). The [[Unified Modeling Language|UML]] [[sequence diagram]] shows the run-time interactions: The <code>Client</code> object traverses the elements of an object structure (<code>ElementA,ElementB</code>) and calls <code>accept(visitor)</code> on each element. <br> First, the <code>Client</code> calls <code>accept(visitor)</code> on <code>ElementA</code>, which calls <code>visitElementA(this)</code> on the accepted <code>visitor</code> object. The element itself (<code>this</code>) is passed to the <code>visitor</code> so that it can "visit" <code>ElementA</code> (call <code>operationA()</code>). <br> Thereafter, the <code>Client</code> calls <code>accept(visitor)</code> on <code>ElementB</code>, which calls <code>visitElementB(this)</code> on the <code>visitor</code> that "visits" <code>ElementB</code> (calls <code>operationB()</code>). === Class diagram === [[File:Visitor design pattern.svg|frame|none|Visitor in [[Unified Modeling Language]] (UML).<ref>{{Cite book |last=Reddy |first=Martin |url=https://www.worldcat.org/oclc/704559821 |title=API design for C++ |date=2011 |publisher=Morgan Kaufmann |isbn=978-0-12-385004-1 |location=Boston |oclc=704559821}}</ref>{{Rp|page=381}}]] [[File:Visitor pattern class diagram in LePUS3.gif|frame|none|Visitor in [[Lepus3|LePUS3]] ([http://lepus.org.uk/ref/legend/legend.xml legend])]]
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)