"The demand for software has grown far faster than our ability to produce it. Furthermore,the Nation needs software that is far more usable,reliable,and powerful than what is being produced today. We have become dangerously dependent on large software systems whose behavior is not well understood and which often fail in unpredicted ways."
Object
. So, a container that takes elements of
type Object
is as polymorphic as can be.public
so
it can be accessed by any one.public
so anyone can access them.private
so it can only be accessed from
within the class protected
so it can be accessed from
within the package or by a descendent class.
System.out.println ("Starting download");
public class StandardOutReporter { public static void report (String msg){ System.out.println (msg); } }
public class StandardOutReporter { public static void report (String msg){ System.out.println (msg + at: +new Date ()); } }
static
. 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. Reporter
around could be a
pain. public class StaticReporter { static Reporter r; static void setReporter (Reporter r){ this.r =r; } static void report (String msg){ r.report (msg); } }
//at the start of the program StaticReporter.setReporter (new StandardOutReporter ()); //later on... void download (...){ StaticReporter.report ( Starting downloading ); ....};
This talk available at http://jmvidal.cse.sc.edu/talks/decoupling/
Copyright © 2009 José M. Vidal
.
All rights reserved.
12 January 2005, 02:21PM