Created
June 3, 2019 09:32
-
-
Save dnivra26/8556e5a28fe0e5729aafc923e41ad74f 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
import java.io.FileWriter; | |
public class Blog { | |
String title = "Microservices"; | |
String author = "Feynmann"; | |
public String getTitle() { | |
return title; | |
} | |
public String getAuthor() { | |
return author; | |
} | |
} | |
interface Printer { | |
public void print(Blog blog); | |
} | |
class CLIPrinter implements Printer { | |
@Override | |
public void print(Blog blog) { | |
System.out.println(blog.getAuthor() + "-" + blog.getTitle()); | |
} | |
} | |
interface Persist { | |
public void save(Blog blog); | |
} | |
class FilePersist implements Persist { | |
@Override | |
public void save(Blog blog) { | |
try { | |
FileWriter fw = new FileWriter(blog.getTitle() + "-" + blog.getAuthor() + ".txt"); | |
fw.write(blog.getTitle() + "-" + blog.getAuthor()); | |
fw.close(); | |
} catch (Exception e) { | |
System.out.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment