Posts Tagged ‘Strategy Pattern’

The Strategy Pattern (Part 1)

Saturday, February 21st, 2009

The Strategy Pattern is more useful for programming languages that do not support first-class functions. Fortunately, JavaScript treats everything as an object, and allows for run-time object modification. That enables the use of the strategy pattern quite nicely.

Here’s a simple example for changing the behavior of an object without hard-coding the behavior options into the object itself. It allows for flexible changing of object behavior down the road, without having to refactor an entire code block.

(more…)