What is the difference between a class library and a framework

I hear the whole day the terms class library, base class library, Framework, ...
What highlights a framework and what a base class library?


The distinguishing feature between a class library and a software framework is that in a framework, the flow of control is not determined by the user´s code, but by the framework.

This is also known as Hollywood principle (don´t call us, we call you).

By the way, there is also a nice Wikipedia article on this topic.


You use a class library in writing your code, but you code within a framework.

The term "framework" is meant to invoke a sense of "being within an environment". If I were to put a (limited) analogy to it, I'd say that a class library is like being able to eat cheese and drink wine, whereas a framework is like visiting France; experiencing the culture. The framework is the structure around which you build your program. The class library are the tools you use (possibly within a framework).

Of course, a framework will typically contain libraries of classes. .NET, for instance, has heaps of class libraries which are included in the entire framework.


Library:

It is just a collection of routines (functional programming) or class definitions(object oriented programming). The reason behind is simply code reuse, ie get the code that has already been written by other developers. The classes or routines normally define specific operations in a domain specific area. For example, there are some libraries of mathematics which can let developer just call the function without redo the implementation of how an algorithm works.

Framework:

In framework, all the control flow is already there, and there are a bunch of predefined white spots that we should fill out with our code. A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.

Library,Framework and your Code image representation:

库,框架和你的代码图像关系

KeyDifference:

The key difference between a library and a framework is “Inversion of Control” . When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you. Source.

Relation:

Both of them defined API, which is used for programmers to use. To put those together, we can think of a library as a certain function of an application, a framework as the skeleton of the application, and an API is connector to put those together. A typical development process normally starts with a framework, and fill out functions defined in libraries through API.

Original answer

链接地址: http://www.djcxy.com/p/22954.html

上一篇: 如何在Xcode 4中“添加现有的框架”?

下一篇: 类库和框架有什么区别