Context:

The implementation of part of object behavior varies from object to object, but is known before each object's creation and is never re-configured for it. A fixed strategy.

Challenge:

  • To integrate the strategy type with the client type.
  • To eliminate the cost of run-time polymorphism in the communication between them. (E.g. formatting, localization, comparison).

Skill:

Participants:

Context:

Does part of its job by consulting an internal Policy.

Policy:

A collection of methods on one facet of Context implementation, used in Context. Policy methods are typically short and inline.

Signature:

Context is parameterized over Policy type. Context contains Policy.

Used by:

Localization, configurable low-level types.

Source:

C++, Alexandrescu.

Scope:

Languages that support genericity.