- Forward


The Strategy 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
Define a family of interchangeable algorithms for accomplishing the same objective
Examples of Use
Back SMYC Forward
  • Line search algorithms in multi-dimensional optimization
  • Different text formatting algorithms
  • Different metrics for finding the distance betwee, for example, colors
A Model of the Strategy Pattern
Back SMYC Forward

In UML

strategy_pattern
An Example of the Strategy Pattern
Back SMYC Forward

In UML

strategy_example_ECMAscript
An Example of the Strategy Pattern (cont.)
Back SMYC Forward

The Person Class

ecmascriptexamples/strategy/Person.js (Fragment: Person)
 

The Comparators

ecmascriptexamples/strategy/Person.js (Fragment: Comparators)
 

The Context

ecmascriptexamples/strategy/Context.js
 
There's Always More to Learn
Back -