Skip to content

Instantly share code, notes, and snippets.

@mikaa123
Created March 8, 2013 17:15
Show Gist options
  • Save mikaa123/5118094 to your computer and use it in GitHub Desktop.
Save mikaa123/5118094 to your computer and use it in GitHub Desktop.
strategies and if statements
var greeters = [
new Greeter(new BoredGreetingStrategy()),
new Greeter(new PoliteGreetingStrategy()),
new Greeter(new FriendlyGreetingStrategy()),
];
greeters.forEach(function(greeter) {
// Since each greeter knows its strategy, there's no need
// to do any type checking. We just greet, and the object
// knows how to handle it.
greeter.greet();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment