SE450: Composite Pattern [43/72] Previous pageContentsNext page

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

Previous pageContentsNext page