Pattern name: Selective Visitor

Intent

Loosely couple behavior modification to behavior and 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 a kind of context objects as described in [CONTEXT].
We call them visitor objects.
http://www.ccs.neu.edu/research/demeter/course/f96/APbookWithDemJava.html


Consequences

Easy behavior adjustments.

Allows to use the behavior modification in other situations.

Does not strongly tie behavior modification to the modified program.



Implementation

Use wrappers as in propagation patterns.

Use context tables as proposed in [CONTEXT]. 

Use the translation approach as in Demeter/Java:
http://www.ccs.neu.edu/home/lieber/Demeter-and-Java.html


Known Uses

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

The Selective Visitor pattern (with the wrapper implementation)
is used extensively in the implementation
of the Demeter Tools/C++. 


Sample Code

See [CONTEXT].

Related patterns:
Visitor (from GOF), Inventor's Paradox, 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).


Exercise:

Define a notation to express visitor classes.
See:
http://www.ccs.neu.edu/research/demeter/biblio/context.html


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)

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