Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created March 20, 2025 23:57
Show Gist options
  • Save trikitrok/bb375db749ba7ddd2904ade0d3e68376 to your computer and use it in GitHub Desktop.
Save trikitrok/bb375db749ba7ddd2904ade0d3e68376 to your computer and use it in GitHub Desktop.
// 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