c++ brought into vogue the concept of interfaces, abstractness, and implementations. java went a step further and formalized them with proper keywords for each of the concepts. there are a substantial number of patterns in which interfaces, abstract classes, and classes can be combined for various purposes. you only have to look at the book design patterns, by erich gamma et al (addison-wesley), to realize the importance of recognizing these constructs.
constructing a software program that you expect to have a long life is an attempt to evolve its functionality over time, without abandoning older behavior for backward compatibility. this is a lot more essential when youre designing libraries and frameworks. the newer libraries should work with older systems that were designed for the older releases of a library. here are some concrete examples of why this is important and how to accomplish this in situations where every programmer is encouraged to adapt the scheme owing to its simplicity.
what is evolving functionality?
{ 【程序编程相关:SOApbox @ JDJ】 to understand what evolving functionality is, lets walk through the design of a very simple class in java. heres the class: class logfacility 【推荐阅读:The Tool I Really Wa】 { 【扩展信息:eBay, Web Services, 】 public log(final string message) // implementation } } logfacility provides a mechanism to log messages. everyone on the team would use this functionality as follows: logfacility lf = new logfacility() lf.log("log this message for me");as its simple and useful, its hard to argue against it. now i take this utility and ship it to two different teams. one team wants to log to a file and the other to stdout. i improvised and came up with stdoutlogfacility and filelogfacility, and suggested that the programmer use the appropriate logging facility as follows: stdoutlogfacility lf = new
stdoutlogfacility(); lf.log("log this message for me"); filelogfacility lf = new filelogfacility(); lf.log("log this message for me"); youd quickly realize that irrespective of what log facility is constructed, it gets used the same way. this is a cue to design an interface for the usage of the log facility as follows: public interface ilogfacility { public log(final string message); } stdoutlogfacility and filelogfacility would implement this interface. in this scenario the programmer would do the following: ilogfacility lf = new stdoutlogfacility(); lf.log("log this message for me"); ilogfacility lf = new filelogfacility(); lf.log("log this message for me"); as you can see, irrespective of the nature of the construction, an object of type ilogfacility ... 下一页