Created
May 26, 2016 15:39
-
-
Save lucasprag/ddd6739d9c981e08afc93a4a2f4850d0 to your computer and use it in GitHub Desktop.
key chain with polymorphism and single responsibility
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 BedroomKeyGenerator | |
def self.generate | |
"algorithm of bedroom key" * 3 | |
end | |
end | |
class FrontDoorKeyGenerator | |
def self.generate | |
"algorithm of front_door key" * 3 | |
end | |
end | |
class BathroomKeyGenerator | |
def self.generate | |
"algorithm of bathroom key" * 3 | |
end | |
end | |
class KeyChain | |
def initialize(door) | |
@door = door | |
end | |
def get | |
{ | |
bedroom: BedroomKeyGenerator, | |
front_door: FrontDoorKeyGenerator, | |
bathroom: BathroomKeyGenerator | |
}.fetch(door).generate | |
end | |
private | |
attr_reader :door | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment