框架、工具包和库之间的区别是什么?


当前回答

Barrass提供的答案可能是最完整的。然而,解释可以很容易地说得更清楚。大多数人忽略了一个事实,即这些都是嵌套的概念。所以让我告诉你吧。

编写代码时:

eventually you discover sections of code that you're repeating in your program, so you refactor those into Functions/Methods. eventually, after having written a few programs, you find yourself copying functions you already made into new programs. To save yourself time you bundle those functions into Libraries. eventually you find yourself creating the same kind of user interfaces every time you make use of certain libraries. So you refactor your work and create a Toolkit that allows you to create your UIs more easily from generic method calls. eventually, you've written so many apps that use the same toolkits and libraries that you create a Framework that has a generic version of this boilerplate code already provided so all you need to do is design the look of the UI and handle the events that result from user interaction.

一般来说,这完全解释了术语之间的差异。

其他回答

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.

总结一下:你的代码调用一个库,而框架调用你的代码。

非常非常相似,框架通常比库更完善和完整,而工具包可以简单地是类似库和框架的集合。

这是一个非常好的问题,在本质上可能有一点点主观,但我相信这是我能给出的最好的答案。

如果你是一个视觉学习者,下面的图表会让你更清楚:

(学分:http://tom.lokhorst.eu/2010/09/why-libraries-are-better-than-frameworks)

我认为这有点主观。工具箱是最简单的。它只是一堆可以使用的方法和类。 库和框架的区别在于如何使用它们。很久以前,我在某个地方读到一个完美的答案。框架调用您的代码,但另一方面,您的代码调用库。

框架:安装在你的机器上,允许你与它交互。没有这个框架,你就不能向你的机器发送编程命令

库:旨在解决某一问题(或同一类别的若干问题)

工具包:许多代码片段的集合,可以在多个问题上解决多个问题(就像工具箱一样)