Pattern name: Selective Visitor

Intent

Loosely couple traversal modification to structure. 

Write an editing program instead of editing the program yourself.
Reuse editing program later.

Also Known As:

Structure-shy behavior modification, Event-based coupling, Context


Motivation

Define collaborative behavior modification in one place
instead of spreading it over the program.
Selective Visitor let's you write behavior modifications
with minimal dependency on the class structure.

Modify the behavior of a traversal function call without changing 
the function directly.


Applicability

A traversal function call needs to do additional work.
Express behavior which needs to be executed in addition
to a traversal.

Use the pattern when you need to change the behavior of a group
of classes without changing the classes.

Solution

Use visitor objects as described in the DJ home page.


Consequences

Easy behavior adjustments.

Allows to use the traversal modification in other situations.

Does not strongly tie behavior modification to the modified program.



Implementation

See DJ home page.

Known Uses

Visitor objects in the Visitor pattern of GOF use a primitive
form of the Selective Visitor pattern.

The Selective Visitor pattern 
is used extensively in the implementation
of the Demeter Tools/C++ and Demeter/Java. 


Sample Code

See DJ.

Related patterns:
Visitor (from GOF), Structure-shy Traversal.

Selective Visitor is an improved form of the Visitor pattern from GOF.
The Visitor pattern is clumsy to use and does not support evolution
of the class graph.
See
http://www.ccs.neu.edu/research/demeter/biblio/context.html

See
http://www.ccs.neu.edu/research/demeter/adaptive-patterns/index.html
for related work on the visitor pattern (select visitor usage
discussion).


References:

CONTEXT:
@INPROCEEDINGS{spl:context-conf,
AUTHOR = "Linda M. Seiter and Jens Palsberg and Karl J. Lieberherr",
TITLE = "{Evolution of Object Behavior using Context Relations}",
BOOKTITLE = "Symposium on Foundations of Software Engineering",
YEAR = "1996",
ADDRESS = "San Francisco",
PAGES = "",
EDITOR = "David Garlan",
PUBLISHER = "ACM Press"
}                                
(see URL: ftp://ftp.ccs.neu.edu/pub/people/lieber/context.ps)

==========================================================================