the strategy, template method, and bridge patterns
to illustrate the strategy pattern lets assume that we are working on a debug logger. debug loggers are often very useful devices. programmers can send messages to these loggers at strategic places within the code. if the system misbehaves in some way, the debug log can provide clues about what the system was doing internally at the time of the failure. 【程序编程相关:谨慎使用Date和Time类】
one of the great benefits of object-oriented programming is polymorphism; i.e., the ability to send a message to an object without knowing the true type of the object. perhaps no pattern illustrates this better than the strategy pattern. 【推荐阅读:使用Properties类带来的好处】
logger.log("my message");on the other hand, what we want to see in the log is quite a bit more complex. at very least we are going to want to see the time and date of the message. well also probably want to see the thread id. indeed, there may be a whole laundry list of system states that we want to log along with the message. so the logger needs to gather all of this peripheral information together, format it into a log message, and then add it to the growing list of logged messages. 【扩展信息:Jar clone的版本冲突】
in order to be effective, loggers need to be simple for programmers to use. programmers arent going to frequently use something that is inconvenient. you should be able to emit a log message with something no more complicated than:
... 下一页