.

Context:

"Dynamic classification": The implementation of object functionality, possibly related to internal representation (e.g. number internal representation) is determined during object creation time and may change later due to assignment.

Challenge:

To separate the interface from implementation, possibly allowing the replacement of the latter.

Skill:

Participants:

Context:

Used by Client, typically non-polymorphically. Responsible for constructing the appropriate Implementation (normally, understood from argument) and replacing it (typically, due to assignment). (E.g. Number, hiding internal number representation, constructed according to numeric-constant argument.)

Implementation:

Internal representation, hidden inside Context. The capability to do the actual work in Context. (E.g. to execute arithmetic operations in Number.)

Concrete Implementation:

Constructed by Context. (E.g. Integer or Real in Number.) Responsible for doing the actual work in Context.

Signature:

Context contains Implementation and represents it.

Used patterns and idioms:

(Optionaly) Double Dispatch idiom, (optionally) Algebraic Hierarchy.

Comment:

A simplified form of the GOF pattern by the same name (lacking the Concrete Behavior).

Source:

Coplien.

Scope:

General.