Skip to content

Instantly share code, notes, and snippets.

@dnivra26
Last active June 5, 2019 14:17
Show Gist options
  • Save dnivra26/4a2307392b55ed738ddc0e5e4378cecd to your computer and use it in GitHub Desktop.
Save dnivra26/4a2307392b55ed738ddc0e5e4378cecd to your computer and use it in GitHub Desktop.
class BookDB {
BookPersist bookPersist;
public void save(Book book) {
bookPersist.save(book);
}
}
interface BookPersist {
public void save(Book book);
}
class FilePersist implements BookPersist {
@Override
public void save(Book book) {
try {
FileWriter fw = new FileWriter("books.txt");
fw.write(book.getTitle() + "-" + book.getAuthor());
fw.close();
} catch (Exception e) {
System.out.println(e);
}
System.out.println("Success...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment