Last active
March 20, 2025 23:11
-
-
Save trikitrok/2bc194f1f8c0b50cfbbd60f3d4833098 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
class Library { | |
private display: Display; | |
constructor(display: Display) { | |
this.display = display; | |
} | |
printBooks(books: Book[]): void { | |
const inputReader = new ConsoleInputReader(); // creating the ConsoleInputReader here impedes unit testing | |
const libraryName = inputReader.readLine(); | |
this.display.show(libraryName); | |
for (const book of books) { | |
this.display.show(book.getName()); | |
} | |
} | |
} | |
////////////////////////////////////////////// | |
// After parameterizing the method | |
class Library { | |
private display: Display; | |
constructor(display: Display) { | |
this.display = display; | |
} | |
// !! Method was parameterized and now we can test it | |
// passing a test double that overrides `readLine(): string;` | |
printBooks(books: Book[], inputReader: ConsoleInputReader): void { | |
const libraryName = inputReader.readLine(); | |
this.display.show(libraryName); | |
for (const book of books) { | |
this.display.show(book.getName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment