Forked from joebew42/layers_and_boundaries.rb
Last active
September 17, 2021 06:34
-
-
Save xpepper/189621ab3463685495930801aa41f507 to your computer and use it in GitHub Desktop.
A code-ish description of the example depicted in the chapter 25 ("Layers and Boundaries") of "Clean Architecture" book by Bob Martin
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 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