Last active
November 22, 2021 10:18
-
-
Save joebew42/d93d3ffaefd781d152df855236c529e2 to your computer and use it in GitHub Desktop.
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
interface GameRulesInputBoundary | |
void moveSouth() | |
end | |
interface GameRulesOutputBoundary | |
void moveSouthSucceed() | |
end | |
class GameRules implements GameRulesInputBoundary | |
def init(GameRulesOutputBoundary outputBoundary) | |
this.outputBoundary = outputBoundary | |
end | |
@override | |
def moveSouth() | |
# do business logic | |
this.outputBoundary.moveSouthSucceed() | |
end | |
end | |
----------------------- | |
interface LanguageInputBoundary | |
void parse(message) | |
end | |
interface LanguageOutputBoundary | |
void movementSucceed() | |
end | |
class ItalianLanguageOutputBoundary implements GameRulesOutputBoundary | |
def init(LanguageOutputBoundary languageOutputBoundary) | |
this.languageOutputBoundary = languageOutputBoundary | |
end | |
@override | |
void moveSouthSucceed() | |
this.languageOutputBoundary.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 | |
------------------------- | |
interface TextDeliveryInputBoundary | |
void read_message() | |
end | |
class ConsoleTextDeliveryInputBoundary implements TextDeliveryInputBoundary | |
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 languageOutputBoundary = new ConsoleTextDeliveryOutputBoundary() | |
GameRulesOutputBoundary gamerulesOutputBoundary = new ItalianLanguageOutputBoundary(languageOutputBoundary) | |
GameRulesInputBoundary gamerules = new GameRules(gamerulesOutputBoundary) | |
LanguageInputBoundary languageInputBoundary = new ItalianLanguageInputBoundary(gamerules) | |
TextDeliveryInputBoundary 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