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

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


当前回答

我认为主要的区别是框架遵循“好莱坞原则”,即。“别打给我们,我们会打给你的。”

马丁·福勒说:

库本质上是一组 你可以调用的函数 日子通常安排在课堂上。 每个调用都做一些工作并返回 控件到客户端。 框架体现了一些抽象 设计,内置了更多的行为。 为了使用它,你需要插入 你的行为变成了各种各样的地方 框架可以通过子类化或 通过插入你自己的类。的 框架的代码然后调用你的代码 在这些点上。

其他回答

库执行特定的、定义良好的操作。

框架是一个骨架,应用程序通过填充骨架来定义操作的“肉”。框架仍然有代码来连接各个部分,但最重要的工作是由应用程序完成的。

库的例子:网络协议、压缩、图像处理、字符串实用程序、正则表达式计算、数学。操作是独立的。

框架示例:Web应用程序系统,插件管理器,GUI系统。框架定义概念,而应用程序定义最终用户关心的基本功能。

你的解释听起来不错。库可以是任何经过编译和自包含的东西,以便在其他代码中重用,实际上对其内容没有任何限制。

另一方面,框架应该具有一系列用于应用程序开发的特定领域的功能,就像您的示例MVC一样。

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

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.

我认为库是一组实现目标的实用程序(例如,套接字,加密等)。

框架是库+运行时环境。例如,ASP。NET是一个框架:它接受HTTP请求、创建页面对象、调用生命周期事件等等。框架完成了所有这些工作,您编写了一些代码,这些代码将在当前请求生命周期的特定时间运行!

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

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