Connexions

Sections
You are here: Home » Content » Visitor Design Pattern

About: Visitor Design Pattern

Module by: Dung Nguyen. E-mail the author

View the content: Visitor Design Pattern

Metadata

Name: Visitor Design Pattern
ID: m16707
Language: English (en)
Summary: Using the interpreter pattern to implement the overall behavior of a composite structure such as the list structure has one glaring drawback: it presents a static non-extensible interface to the client that cannot handle unforeseen future requirements. Each time a new behavior is needed to process the composite structure, new methods have to be added to the structure. As a result, the task of maintaining the code can quickly become unmanageable. The root of this problem comes from the lack of delineation between the intrinsic and primitive behaviors of the structure itself and its non-primitive application specific behaviors. The visitor design pattern offers a solution to this problem by decoupling these two kinds of behaviors into two separate systems of classes, hosts and visitors, that communicate with each other via only their public interfaces. Here the hosts are the composite structure with its invariant structural behaviors and the visitors are the infinitely varying algorithms that are to be performed on the structure. This approach turns a composite structure into a framework where control is inverted: one hands an algorithm to the structure to be executed instead of handing a structure to an algorithm to perform a computation. The structure is capable of carrying out any conforming algorithm, past, present, or future. Such a system of co-operating objects that is not only reusable and extensible, but also easy to understand and maintain.
Subject: Science and Technology
Keywords: Algorithm, Decoupling, Design, Pattern, Structure, Visitor
Document Type: -//CNX//DTD CNXML 0.5 plus MathML//EN
License: Creative Commons Attribution License CC-BY 2.0

Authors: Dung Nguyen (dxnguyen@rice.edu)
Copyright Holders: Dung Nguyen (dxnguyen@rice.edu)
Maintainers: Dung Nguyen (dxnguyen@rice.edu)

Latest version: 1.1 (history)
First publication date: Feb 7, 2008 1:52 pm -0600
Last revision to module: Jun 18, 2008 2:35 pm -0500

Downloads

PDF: m16707_1.1.pdf PDF file, for viewing content offline and printing. Learn more.
XML: m16707_1.1.cnxml XML that defines the structure and contents of the module, minus any included media files. Can be reimported in the editing interface. Learn more.

Version History

Version: 1.3 May 13, 2013 1:23 pm -0500 by Stephen Wong
Changes:
fixed code formatting problems in PDF

Version: 1.2 May 12, 2013 12:46 pm -0500 by Dung Nguyen
Changes:
add SBW to roles

Version: 1.1 Jun 18, 2008 2:35 pm -0500 by Dung Nguyen Currently viewing this version.
Changes:
This is the first version.

How to Reuse and Attribute This Content

If you derive a copy of this content using a Connexions account and publish your version, proper attribution of the original work will be automatically done for you.

If you reuse this work elsewhere, in order to comply with the attribution requirements of the license (CC-BY 2.0), you must include

  • the authors' names: Dung Nguyen
  • the title of the work: Visitor Design Pattern
  • the Connexions URL where the work can be found: http://cnx.org/content/m16707/1.1/

See the citation section below for examples you can copy.

How to Cite and Attribute This Content

The following citation styles comply with the attribution requirements for the license (CC-BY 2.0) of this work:

American Chemical Society (ACS) Style Guide:

Nguyen, D. Visitor Design Pattern, Connexions Web site. http://cnx.org/content/m16707/1.1/, Jun 18, 2008.

American Medical Assocation (AMA) Manual of Style:

Nguyen D. Visitor Design Pattern [Connexions Web site]. June 18, 2008. Available at: http://cnx.org/content/m16707/1.1/.

American Psychological Assocation (APA) Publication Manual:

Nguyen, D. (2008, June 18). Visitor Design Pattern. Retrieved from the Connexions Web site: http://cnx.org/content/m16707/1.1/

Chicago Manual of Style (Bibliography):

Nguyen, Dung. "Visitor Design Pattern." Connexions. June 18, 2008. http://cnx.org/content/m16707/1.1/.

Chicago Manual of Style (Note):

Dung Nguyen, "Visitor Design Pattern," Connexions, June 18, 2008, http://cnx.org/content/m16707/1.1/.

Chicago Manual of Style (Reference, in Author-Date style):

Nguyen, D. 2008. Visitor Design Pattern. Connexions, June 18, 2008. http://cnx.org/content/m16707/1.1/.

Modern Languages Association (MLA) Style Manual:

Nguyen, Dung. Visitor Design Pattern. Connexions. 18 June 2008 <http://cnx.org/content/m16707/1.1/>.