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!
=== Iteration loops === {{See also|Iterator pattern}} The visitor pattern may be used for iteration over [[Container (abstract data type)|container]]-like data structures just like [[Iterator pattern]] but with limited functionality.<ref name="Budd1997">{{Cite book |last=Budd |first=Timothy |url=https://www.worldcat.org/oclc/34788238 |title=An introduction to object-oriented programming |date=1997 |publisher=Addison-Wesley |isbn=0-201-82419-1 |edition=2nd |location=Reading, Mass. |oclc=34788238}}</ref>{{Rp|page=288}} For example, [[iteration]] over a directory structure could be implemented by a function class<!-- <- this is not a mistake, it means class Function {...} --> instead of more conventional [[Loop (programming)|loop pattern]]. This would allow deriving various useful information from directories content by implementing a visitor functionality for every item while [[Code reuse|reusing]] the iteration code. It's widely employed in Smalltalk systems and can be found in C++ as well.{{r|Budd1997|p=289}} A drawback of this approach, however, is that you can't break out of the loop easily or iterate concurrently (in parallel i.e. traversing two containers at the same time by a single {{Code|i}} variable).{{r|Budd1997|p=289}} The latter would require writing additional functionality for a visitor to support these features.{{r|Budd1997|p=289}}
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)