Factory Methods - III
7 September 2008Implementation that prints messages on command prompt is presented in this post.
public class SystemTrace implements Trace { private boolean debug; public void setDebug( boolean debug ) { this.debug = debug; } public void debug( String message ) { if( debug ) { // only print if debug is true System.out.println( "DEBUG: " + message ); } } public void error( String message ) { // always print out errors System.out.println( "ERROR: " + message ); } }
To use SystemTrace, we will do the following:
… SystemTrace log = new SystemTrace(); … log.debug( "entering log" ); …
This approach has drawbacks discussed in next post.
Continued …
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Factory Methods - III