Decouple With Interface
File: Main.java public class Main { public static void main(String[] a) { MessageData source = new SimpleMessageData("Hello, world"); MessageReporter destination = new StdoutMessageReporter(); destination.write(source.getMessage()); } } interface MessageReporter { void write(String message); } interface MessageData { String getMessage(); } class StdoutMessageReporter implements MessageReporter { public void write(String message) { System.out.println(message); } } class SimpleMessageData implements MessageData { private final String message; public SimpleMessageData() { this("Hello, world"); } public SimpleMessageData(String message) { this.message = message; } public String getMessage() { return this.message; } }