Created
March 8, 2013 17:15
-
-
Save mikaa123/5118094 to your computer and use it in GitHub Desktop.
strategies and if statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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