Containers and Components

Composite Pattern

Context

  1. Primitive objects can be combined to composite objects
  2. Clients treat a composite object as a primitive object

Solution

  1. Define an interface type that is an abstraction for the primitive objects
  2. Composite object collects primitive objects
  3. Composite and primitive classes implement same interface type.
  4. When implementing a method from the interface type, the composite class applies the method to its primitive objects and combines the results

Composite Pattern

.

Composite Pattern

Name in Design Pattern
Actual Name (AWT components)
Primitive
Component
Composite
Container
Leaf
a component without children (e.g. JButton)
method()
a method of Component (e.g. getPreferredSize)


Maintained by John Loomis, last updated 25 February 2007