框架和库之间的区别是什么?

我一直认为库是一组对象和函数,专注于解决特定的问题或应用程序开发的特定领域(即数据库访问);另一方面,框架是一个以特定方法论(即MVC)为中心的库的集合,它涵盖了应用程序开发的所有领域。


当前回答

我会像你五岁一样解释。(没有使用编程术语。)

让我们想象一下,你不久前在你的城市开了一家汉堡店。但是作为初学者,你会觉得做汉堡太难了。你在想一种为顾客做汉堡的简单方法。 有人告诉你,如果你使用框架,你可以很容易地做bugger。你要知道有麦当劳汉堡框架和汉堡王汉堡框架。

如果你使用麦当劳汉堡框架,做巨无霸汉堡就很容易了。(但你不能做皇堡。)

如果你使用汉堡王汉堡框架,就可以很容易地做出皇堡。(但是你不能做巨无霸)

不管怎样,最后,它们都是汉堡。这里很重要的一点是,你必须遵循他们的框架规则来做汉堡。否则,你会觉得更难完成或者根本无法完成。

你也听说过有一种叫做简单汉堡-帕蒂图书馆的东西。

如果你使用这个库,你可以很容易地做出任何汉堡肉饼(X2速度)。 使用麦当劳汉堡框架还是汉堡王汉堡框架并不重要。 无论哪种方式,您仍然可以使用这个简单汉堡-帕蒂库。(即使你没有框架也可以使用这个库。)

你现在看到框架和库的区别了吗?


一旦你开始使用麦当劳汉堡框架。要切换到汉堡王的汉堡框架并不容易。既然你要把整个厨房都换了。

如果您开始使用Java Spring框架构建Web应用程序,那么稍后将很难(也许不可能)更改为Ruby on Rails框架。

但是Library,换别人会容易得多。或者你可以不用它。

其他回答

这是我的想法(其他人也对此进行了合理化解释):

库是包含在代码中的东西。框架是应用程序的容器。

库——任何一组类或组件,只要客户端认为合适,就可以使用它们来完成某个任务。 框架——要求你将某些指导方针“插件”到比你更大的东西中。您只需以一种已发布的必需方式提供特定于您的应用程序/需求的部分,以便“框架可以使您的生活变得轻松”。

从Web开发人员的角度来看:

库可以很容易地被另一个库替换。但框架不能。 如果你不喜欢jquery日期选择器库,你可以替换为其他日期选择器,如bootstrap日期选择器或pickadate。 如果你不喜欢在AngularJS上构建你的产品,你不能用任何其他框架来替代。你必须重写你的整个代码库。 大多数情况下,与框架相比,库需要更少的学习曲线。例如:underscore.js是一个库,Ember.js是一个框架。

实际上,根据使用的上下文,这些术语可以有很多不同的含义。

For example, on Mac OS X frameworks are just libraries, packed into a bundle. Within the bundle you will find an actual dynamic library (libWhatever.dylib). The difference between a bare library and the framework on Mac is that a framework can contain multiple different versions of the library. It can contain extra resources (images, localized strings, XML data files, UI objects, etc.) and unless the framework is released to public, it usually contains the necessary .h files you need to use the library.

Thus you have everything within a single package you need to use the library in your application (a C/C++/Objective-C library without .h files is pretty useless, unless you write them yourself according to some library documentation), instead of a bunch of files to move around (a Mac bundle is just a directory on the Unix level, but the UI treats it like a single file, pretty much like you have JAR files in Java and when you click it, you usually don't see what's inside, unless you explicitly select to show the content).

维基百科称框架为“流行词”。它将软件框架定义为

软件框架是可重用的 为软件系统(或 子系统)。软件框架可以 包括支持程序、代码 库、脚本语言或 其他软件帮助开发和 把不同的组件粘合在一起 软件项目的。各个部分 框架的部分可能是公开的 通过一个API..

所以我认为图书馆就是“一个图书馆”。它是对象/函数/方法的集合(取决于你的语言),你的应用程序“链接”到它,因此可以使用对象/函数/方法。它基本上是一个包含可重用代码的文件,通常可以在多个应用程序之间共享(您不必一遍又一遍地编写相同的代码)。

框架可以是您在应用程序开发中使用的所有内容。它可以是一个库,许多库的集合,脚本的集合,或者创建应用程序所需的任何软件。框架是一个非常模糊的术语。

Here's an article about some guy regarding the topic "Library vs. Framework". I personally think this article is highly arguable. It's not wrong what he's saying there, however, he's just picking out one of the multiple definitions of framework and compares that to the classic definition of library. E.g. he says you need a framework for sub-classing. Really? I can have an object defined in a library, I can link against it, and sub-class it in my code. I don't see how I need a "framework" for that. In some way he rather explains how the term framework is used nowadays. It's just a hyped word, as I said before. Some companies release just a normal library (in any sense of a classical library) and call it a "framework" because it sounds more fancy.

正如我一直描述的那样:

图书馆是一个工具。

框架是一种生活方式。

你可以使用任何微小的部分来帮助你。一个你必须将整个项目投入其中的框架。