框架、工具包和库之间的区别是什么?
当前回答
Martin Fowler在他关于反转控制的文章中讨论了库和框架之间的区别:
Inversion of Control is a key part of what makes a framework different to a library. A library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client. A framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points.
总结一下:你的代码调用一个库,而框架调用你的代码。
其他回答
我认为这有点主观。工具箱是最简单的。它只是一堆可以使用的方法和类。 库和框架的区别在于如何使用它们。很久以前,我在某个地方读到一个完美的答案。框架调用您的代码,但另一方面,您的代码调用库。
库和框架之间最重要的区别,实际上是定义性的区别是控制反转。
这是什么意思?好吧,这意味着当你打电话给图书馆时,你是在控制。但是对于框架,控件是反向的:框架调用您。(这就是所谓的好莱坞原则:不要给我们打电话,我们会给你打电话。)这就是框架的定义。如果它没有控制反转,它就不是一个框架。(我在看你,.NET!)
基本上,所有的控制流都已经在框架中,只有一堆预定义的白点,您可以用您的代码填写。
另一方面,库是您可以调用的功能的集合。
I don't know if the term toolkit is really well defined. Just the word "kit" seems to suggest some kind of modularity, i.e. a set of independent libraries that you can pick and choose from. What, then, makes a toolkit different from just a bunch of independent libraries? Integration: if you just have a bunch of independent libraries, there is no guarantee that they will work well together, whereas the libraries in a toolkit have been designed to work well together – you just don't have to use all of them.
但这只是我对这个术语的解释。与定义良好的库和框架不同,我不认为工具包有一个被广泛接受的定义。
Martin Fowler在他关于反转控制的文章中讨论了库和框架之间的区别:
Inversion of Control is a key part of what makes a framework different to a library. A library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client. A framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points.
总结一下:你的代码调用一个库,而框架调用你的代码。
库只是将方法/函数打包到一个包中的集合,可以导入到代码项目中并重用。
A framework is a robust library or collection of libraries that provides a "foundation" for your code. A framework follows the Inversion of Control pattern. For example, the .NET framework is a large collection of cohesive libraries in which you build your application on top of. You can argue there isn't a big difference between a framework and a library, but when people say "framework" it typically implies a larger, more robust suite of libraries which will play an integral part of an application.
我认为工具包和SDK是一样的。它附带文档、示例、库、包装器等。同样,您可以说这与框架是相同的,您可能这样做是正确的。
它们几乎都可以互换使用。
关于Mittag的正确答案:
一个简单的例子。假设您在一个类中实现了ISerializable接口(. net)。你利用了。net的框架特性,而不是库特性。你填上“白点”(就像mittag说的),你就完成了骨架。你必须事先知道框架将如何“反应”你的代码。实际上。net是一个框架,这就是我不同意Mittag观点的地方。
你的问题的完整的答案在本书的第19章(整个章节都是关于这个主题的)中给出了,顺便说一下,这是一本非常好的书(完全不是“只是为了Smalltalk”)。