- Forward


The Composite Pattern in ECMAScript/JavaScript
An Introduction with Examples


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
    • Group "files" and "folders/directories"
One Version
Back SMYC Forward

In UML:

composite
An Example of the Composite Pattern
Back SMYC Forward

A Recipe System

composite_example_ECMAScript
An Example of the Composite Pattern (cont.)
Back SMYC Forward

The Instruction Class Click here for a demonstration.

ecmascriptexamples/composite/Instruction.js
 

The Recipe Class

ecmascriptexamples/composite/Recipe.js
 

The Driver

ecmascriptexamples/composite/Driver.html
 
There's Always More to Learn
Back -