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

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


当前回答

库实现功能的目的很窄,而框架往往是库的集合,为更广泛的特性提供支持。例如,库System.Drawing.dll处理绘图功能,但它只是整个. net框架的一部分。

其他回答

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

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

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

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

我认为你很好地阐述了其中的区别:框架提供了一个我们工作的框架……不知何故,它比简单的库更“有约束”。 框架还应该为一组库添加一致性。

图书馆是为了方便使用和提高效率。例如,您可以说Zend库通过其定义良好的类和函数帮助我们完成不同的任务。而框架通常强制以某种方式实现解决方案,如MVC(模型-视图-控制器)(引用)。它是一个定义良好的系统,用于像MVC一样分配任务。模型包含数据库端,视图用于UI接口,控制器用于业务逻辑。

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

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

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

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.