Forked from joebew42/layers_and_boundaries.rb
Last active
September 16, 2021 18:24
-
-
Save MatteoPierro/705cba195c82805d712324a4e8f8ca24 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
interface GameRulesOutputBoundary | |
void moveSouthSucceed() | |
end | |
interface GameRulesInputBoundary | |
void parse(message) | |
end | |
class GameRules implements GameRulesInputBoundary | |
def init(GameRulesOutputBoundary outputBoundary) | |
this.outputBoundary = outputBoundary | |
end | |
def moveSouth() | |
# do business logic | |
this.outputBoundary.moveSouthSucceed() | |
end | |
end | |
----------------------- | |
interface LanguageOutputBoundary | |
void movementSucceed(message) | |
end | |
interface LanguageInputBoundary | |
void read(message) | |
end | |
class ItalianLanguageOutputBoundary implements GameRulesOutputBoundary | |
def init(LanguageOutputBoundary delivery) | |
this.delivery = delivery | |
end | |
@override | |
void moveSouthSucceed() | |
this.delivery.movementSucceed("Movimento completato") | |
end | |
end | |
class ItalianLanguageInputBoundary implement LanguageInputBoundary | |
def init(GameRulesInputBoundary gamerules) | |
this.gamerules = gamerules | |
end | |
@override | |
def parse(message) | |
if message == "muovi sud" | |
gamerules.moveSouth() | |
end | |
end | |
end | |
------------------------- | |
class ConsoleTextDeliveryInputBoundary | |
def init(LanguageInputBoundary inputBoundary) | |
this.inputBoundary = inputBoundary | |
end | |
@override | |
void read_message | |
message = read_from_command_line | |
inputBoundary.parse(message) | |
end | |
end | |
class ConsoleTextDeliveryOutputBoundary implements LanguageOutputBoundary | |
@override | |
void movementSucceed(message) | |
system.println(message) | |
end | |
end | |
------------ | |
class main | |
def init() | |
LanguageOutputBoundary textDeliveryOutputBoundary = new ConsoleTextDeliveryOutputBoundary() | |
GameRulesOutputBoundary languageOutputBoundary = new ItalianLanguageOutputBoundary(textDeliveryOutputBoundary) | |
GameRules gamerules = new GameRules(languageOutputBoundary) | |
LanguageInputBoundary languageInputBoundary = new ItalianLanguageInputBoundary(gamerules) | |
ConsoleTextDeliveryInputBoundary textDeliveryInputBoundary = new ConsoleTextDeliveryInputBoundary(languageInputBoundary) | |
while true | |
textDeliveryInputBoundary.read_message() | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment