Created
July 20, 2012 18:49
-
-
Save jwilger/3152542 to your computer and use it in GitHub Desktop.
TDA, no mutation, no (used) return values between objects
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
class Printer | |
def initialize(options) | |
@out = options.fetch(:out) | |
@translator = options.fetch(:translator) | |
end | |
def say_hello | |
@translator.translate("Hello!", self) | |
end | |
def receive_translation(translated_text) | |
@out.puts(translated_text) | |
end | |
end | |
class Translator | |
def translate(text, observer) | |
observer.receive_translation(translations[text]) | |
end | |
private | |
def translations | |
{'Hello!' => 'Guten tag!', 'Foo' => 'Bar'} | |
end | |
end | |
translator = Translator.new | |
printer = Printer.new(out: STDOUT, translator: translator) | |
printer.say_hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment