- Forward


The Composite Pattern
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Motivation
Back SMYC Forward
  • The Need:
    • Ignore differences between individual objects and compositions of objects
  • Examples:
    • Group "primitive" shapes in a drawing application
    • Group "rolling stock" in a locomotive scheduling application
One Version
Back SMYC Forward

In UML:

composite
An Example
Back SMYC Forward

A Message Distribution System

composite_example
An Example (cont.)
Back SMYC Forward
javaexamples/composite/Distribution.java
 
An Example (cont.)
Back SMYC Forward
javaexamples/composite/DistributionList.java
 
An Example (cont.)
Back SMYC Forward
javaexamples/composite/Driver.java
 
There's Always More to Learn
Back -