Content deleted Content added
fixed spelling of responsibility |
|||
Line 9:
=== Java ===
The following Java code illustrates the pattern with the example of a logging class. Each logging handler decides if any action is to be taken at this log level and then passes the message on to the next logging handler. The output is:
Writing to debug output: Entering function
Writing to debug output: Step1 completed.
Writing to stderr: Step1 completed.
Line 19:
import java.util.*;
public static int ERR = 3;
public static int NOTICE = 5;
Line 31:
}
public DebugLogger(int mask) { this.mask = mask; }
Line 40:
}
public EMailLogger(int mask) { this.mask = mask; }
Line 49:
}
public StderrLogger(int mask) { this.mask = mask; }
Line 58:
}
public static void main(String[] args) {
// building the chain of responsibility
Line 65:
new StderrLogger(Logger.NOTICE) ) );
l.message("Entering function
l.message("Step1 completed.", Logger.NOTICE); ''// handled by Debug- and StderrLogger''
l.message("An error has occurred.", Logger.ERR); ''// handled by all three Logger''
}
}
==See also==
|