04-07-14 04:41 一段关于Framework与L

04-07-14 04:41 一段关于Framework与Library的区别的很好的解释。 Additionally, a framework and library differ in the sense that the former is the latter turned inside out. What I mean is that if you use a library, the calling is done by the client. The calls are distinct and they do what they claim to be doing. In a framework, there are callbacks. Because there are callbacks, one should expect some kind of function pointers, virtual functions or interfaces. In fact, a framework uses polymorphism to let you add your object to the system already in place. A framework, then,is nothing but a structure with most of the plumbing already provided.Since a framework does not know what instance of objects will be added, it relies on the client objects adhering to certain interfaces. Because J2EE consists of callbacks (servlets -> service(Request, Response)), EJBs (ejbLoad, ejbStore, all container callbacks) it is a framework. On the other hand C consists of libraries because the client calls and the library function/method just does its stuff (e.g. atoi or printf in C). In a framework the call sequence is not in your control while in a library, it is. A good example other than above is Swing where you provide certain methods (e.g. getPreferredSize(), getMinimumSize() etc) and you wait to be called. Also, libraries don't maintain state. Frameworks do. Because a framework is a structure (while libraries are building blocks)and  because a structure is difficult to change, bad design of the framework can quickly become difficult to use. An example is MFC framework which while working through callbacks, has a top heavy (meaning the base class consists of most methods) class and this makes it cumbersome to use. HTH, Regards, Kamesh fireshort @ 04-07-14 04:41 返回页首 | 评论 | 引用(0) | 编辑 评论

原始快照:web.archive.org