Last active
April 20, 2018 09:02
-
-
Save thonglinhma/6d326a92799177aa26170aeb99b4fbeb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
abstract class PrintStrategy { | |
String print(String string); | |
} | |
class Printer { | |
PrintStrategy _strategy; | |
Printer({PrintStrategy strategy}) : _strategy = strategy; | |
String print(String string) { | |
return _strategy.print(string); | |
} | |
} | |
class UpperCaseStrategy extends PrintStrategy { | |
@override | |
String print(String string) { | |
return string.toUpperCase(); | |
} | |
} | |
class LowerCaseStrategy extends PrintStrategy { | |
@override | |
String print(String string) { | |
return string.toLowerCase(); | |
} | |
} | |
main(List<String> arguments) { | |
var lower = Printer(strategy: new LowerCaseStrategy()); | |
lower.print("O tempora, o mores!"); | |
var upper = Printer(strategy: new UpperCaseStrategy()); | |
upper.print("O tempora, o mores!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment