Introduction to 492 and Decoupling
public interface Reporter { void report (String msg); }
void download (Reporter r,....){ r.report ( "Starting downloading" ); ...; }
public class StandardOutReporter implements Reporter { public void report (String msg){ System.out.println (msg + " at: " +new Date ()); } }
public class JTextComponentReporter implements Reporter { JTextComponent comp; public JTextComponentReporter (JTextComponent c){ comp =c; } public void report (String msg){ comp.setText (msg + " at: " +new Date ()); } }
Reporter
interface are
de-coupled from its implementation. They don't care if its
writing to stdout or a GUI. 33 of 34