Context:

  1. Heavyweight resources that are referenced by different clients, typically read-only.
  2. Heavyweight objects that are passed and returned by value (in languages that support value addressing).

Challenge:

To avoid redundant storage, as well as its copying and disposal overhead.

Skill:

Participants:

Resource Proxy :

Represents the resource implementation (for its Clients). Responsible for creating the Resource Implementation and notifying it of the duration of the link.

Resource Implementation :

Contains the data and knows the real methods over it. Responsible for actually deleting the resource (i.e. itself).

Signature:

Resource Proxies share a Resource Implementation and represent it.

Used patterns and idioms:

Reference-counting idiom, optionally: Lazy Copy.

Used by:

Flyweight-aided character string.

Scope:

General (system programming).