Slides of the talk I gave at ConFoo Montréal 2019 about "Hexagonal Architecture".
Hexagonal Architecture, Clean Architecture, Domain-Driven Design… You may have heard about them. Let's start from scratch in this session and go beyond the buzzwords. We'll go together though these ideas to understand how you can improve the maintainability of your projects', either greenfield or legacy.
59. import * as fs from "fs";
import * as path from "path";
import ObtainPoems from "!../domain/obtain-poems";
class ObtainPoemsFromFS implements ObtainPoems {
getAPoem() {
const pathToPoem = path.join(!__dirname, "poem.txt");
const poem = fs.readFileSync(pathToPoem, { encoding: "utf8" });
return poem;
}
}
Infra.
59
60. !// 1. Instantiate the right-side adapter(s)
!// 2. Instantiate the hexagon (domain)
!// 3. Instantiate the left-side adapter(s)
60
61. import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
!// 3. Instantiate the left-side adapter(s)
61
62. import PoetryReader from "./domain/poetry-reader";
import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
const poetryReader = new PoetryReader(poetryLibrary);
!// 3. Instantiate the left-side adapter(s)
62
63. import PoetryReader from "./domain/poetry-reader";
import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
import ConsoleApi from "./infrastructure/console-api";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
const poetryReader = new PoetryReader(poetryLibrary);
!// 3. Instantiate the left-side adapter(s)
const consoleApi = new ConsoleApi(poetryReader);
63
64. import PoetryReader from "./domain/poetry-reader";
import ObtainPoemsFromFS from "./infrastructure/obtain-poems-from-fs";
import ConsoleApi from "./infrastructure/console-api";
!// 1. Instantiate the right-side adapter(s)
const poetryLibrary = new ObtainPoemsFromFS();
!// 2. Instantiate the hexagon (domain)
const poetryReader = new PoetryReader(poetryLibrary);
!// 3. Instantiate the left-side adapter(s)
const consoleApi = new ConsoleApi(poetryReader);
!// App logic is only using left-side adapter(s).
console.log("Here is some poetry:n");
consoleApi.ask();
64