Created
March 20, 2025 23:57
-
-
Save trikitrok/bb375db749ba7ddd2904ade0d3e68376 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
// New interface comes from applying Extract Interface to the wrapper | |
interface LibraryData { | |
getLibraryName(): string; | |
} | |
// Notice how we renamed the wrapper to free the interface name | |
class AcmeInputReaderLibraryData implements LibraryData { | |
private readonly inputReader: AcmeInputReader ; | |
constructor(inputReader: AcmeInputReader) { | |
this.inputReader = inputReader; | |
} | |
// moved method | |
getLibraryName(): string { | |
return this.inputReader.readLine(); | |
} | |
} | |
class Library { | |
private display: Display; | |
constructor(display: Display) { | |
this.display = display; | |
} | |
// After applying Parameterize Method and then Extract Interface | |
printBooks(books: Book[], libraryData: LibraryData): void { | |
const libraryName = libraryData.getLibraryName(); | |
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