Computers

Design Patterns : Composite pattern

Motivation

Frequently programmers develop systems in which a component may be an individual object or it may represent a collection of objects.

Intent

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

Applicability

Use the Composite pattern when;

  • You want to represent part-whole hierarchies of objects
  • You want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly.

Diagram

Key concepts

•A composite is a container that may hold either individual objects or other compositions.
•Common behaviors may appear in both individual objects and compositions.

Share this post

Related Posts