Last active
June 5, 2019 14:17
-
-
Save dnivra26/4a2307392b55ed738ddc0e5e4378cecd 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 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