Skip to content

Instantly share code, notes, and snippets.

@dnivra26
Created June 3, 2019 09:32
Show Gist options
  • Save dnivra26/8556e5a28fe0e5729aafc923e41ad74f to your computer and use it in GitHub Desktop.
Save dnivra26/8556e5a28fe0e5729aafc923e41ad74f to your computer and use it in GitHub Desktop.
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