Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileWriter;
- import java.io.IOException;
- interface ILoger {
- void log(final String message);
- }
- class FileLogger implements ILoger {
- private FileWriter fileWriter;
- public FileLogger(final String fName) throws IOException {
- fileWriter = new FileWriter(fName);
- }
- @Override
- public void log(final String message) {
- try {
- fileWriter.write(System.currentTimeMillis() + ": " + message);
- fileWriter.close();
- } catch (Exception e) {
- System.err.println("ERROR: ");
- e.printStackTrace();
- }
- }
- }
- class DataAccessLayer {
- private ILoger loger;
- public DataAccessLayer(final ILoger loger) {
- this.loger = loger;
- }
- public void addClient(final String name) {
- loger.log("added " + name);
- }
- }
- public class Main {
- public static void main(String[] args) throws IOException {
- var fl = new FileLogger("data.txt");
- var dal = new DataAccessLayer(fl);
- dal.addClient("Andrew");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement