System.out.println("--------------- handle A ---------------"); handlerA.handleRequest("A"); System.out.println("--------------- handle B ---------------"); handlerA.handleRequest("B"); System.out.println("--------------- handle Z ---------------"); handlerA.handleRequest("Z"); } }
// 执行结果 // // --------------- handle A --------------- // Concrete Handler A processed... // --------------- handle B --------------- // Concrete Handler A can't process, call other handler... // Concrete Handler B processed... // --------------- handle Z --------------- // Concrete Handler A can't process, call other handler... // Concrete Handler B can't process, call other handler... // Concrete handler z processed...
AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR); AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG); AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);
System.out.println("--------------- handle info ---------------"); loggerChain.logMessage(AbstractLogger.INFO, "This is an information.");
System.out.println("--------------- handle debug ---------------"); loggerChain.logMessage(AbstractLogger.DEBUG, "This is a debug level information.");
System.out.println("--------------- handle Error ---------------"); loggerChain.logMessage(AbstractLogger.ERROR, "This is an error information."); } }
// --------------- handle info --------------- // Standard Console::Logger: This is an information. // --------------- handle debug --------------- // File::Logger: This is a debug level information. // Standard Console::Logger: This is a debug level information. // --------------- handle Error --------------- // Error Console::Logger: This is an error information. // File::Logger: This is an error information. // Standard Console::Logger: This is an error information.