What is the difference between a framework and a library?
框架和库的区别是什么?
I always thought of a library as a set of objects and functions that is focused around solving a particular problem or around a specific area of application development (i.e. database access); a framework on the other hand is a collection of libraries centered around a particular methodology (i.e. MVC) and covers all areas of application development.
我总是把一个库看作是一组对象和函数,它们集中于解决特定的问题或围绕应用程序开发的特定领域(即数据库访问);另一方面,框架是围绕特定方法(即MVC)的库的集合,涵盖了应用程序开发的所有领域。
20 个解决方案
#1
280
Actually these terms can mean a lot of different things depending the context they are used.
实际上,根据使用的上下文,这些术语可能意味着许多不同的东西。
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.
例如,在Mac OS X框架上,仅仅是库,打包成一个包。在bundle中,您将找到一个实际的动态库(libWhatever.dylib)。裸库和Mac框架的区别在于,一个框架可以包含多个不同版本的库。它可以包含额外的资源(图像、本地化的字符串、XML数据文件、UI对象等),除非框架被公开,它通常包含需要使用库的必要的.h文件。
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).
因此你有一切在一个包需要在应用程序中使用图书馆(C / c++ / objective - C库没有. h文件毫无用处,除非你自己写据库文档),而不是一堆文件移动(Mac包只是一个Unix级别的目录,但UI对待它就像一个单一文件,很像你在Java JAR文件当你点击它时,你通常看不到里面有什么,除非您显式选择显示内容)。
Wikipedia calls framework a "buzzword". It defines a software framework as
*将框架称为“时髦词”。它定义了一个软件框架。
A software framework is a re-usable design for a software system (or subsystem). A software framework may include support programs, code libraries, a scripting language, or other software to help develop and glue together the different components of a software project. Various parts of the framework may be exposed through an API..
软件框架是软件系统(或子系统)的可重用设计。软件框架可能包括支持程序、代码库、脚本语言或其他软件,以帮助开发和粘合软件项目的不同组件。框架的各个部分可以通过API公开。
So I'd say a library is just that, "a library". It is a collection of objects/functions/methods (depending on your language) and your application "links" against it and thus can use the objects/functions/methods. It is basically a file containing re-usable code that can usually be shared among multiple applications (you don't have to write the same code over and over again).
所以我认为图书馆就是一个图书馆。它是对象/函数/方法的集合(取决于您的语言)和您的应用程序“链接”,从而可以使用对象/函数/方法。它基本上是一个包含可重用代码的文件,通常可以在多个应用程序之间共享(您不必一次又一次地编写相同的代码)。
A framework can be everything you use in application development. It can be a library, a collection of many libraries, a collection of scripts, or any piece of software you need to create your application. Framework is just a very vague term.
框架可以是应用程序开发中使用的所有内容。它可以是一个库、许多库的集合、一个脚本集合,或者任何需要创建应用程序的软件。框架只是一个非常模糊的术语。
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.
这里有一篇关于“图书馆与框架”主题的文章。我个人认为这篇文章是很有争议的。不过,他说的并不是错误的,他只是挑出了一个框架的多重定义,并将其与经典的库定义进行比较。他说你需要一个子类化的框架。真的吗?我可以在一个库中定义一个对象,我可以链接它,并在我的代码中对它进行子类化。我不认为我需要一个“框架”。在某种程度上,他解释了术语框架是如何被使用的。就像我之前说的,这只是一个炒作的词。有些公司只发布一个普通的库(在任何意义上都是经典的库),并称之为“框架”,因为它听起来更花哨。
#2
415
A library performs specific, well-defined operations.
一个库执行特定的、定义良好的操作。
A framework is a skeleton where the application defines the "meat" of the operation by filling out the skeleton. The skeleton still has code to link up the parts but the most important work is done by the application.
框架是一个框架,应用程序通过填充骨架来定义操作的“肉”。骨架仍然有代码来连接部分,但是最重要的工作是由应用程序完成的。
Examples of libraries: Network protocols, compression, image manipulation, string utilities, regular expression evaluation, math. Operations are self-contained.
库的例子:网络协议、压缩、图像处理、字符串实用程序、正则表达式计算、数学。操作都是独立的。
Examples of frameworks: Web application system, Plug-in manager, GUI system. The framework defines the concept but the application defines the fundamental functionality that end-users care about.
框架示例:Web应用程序系统、插件管理器、GUI系统。框架定义了概念,但是应用程序定义了最终用户关心的基本功能。
#3
233
I think that the main difference is that frameworks follow the "Hollywood principle", i.e. "don't call us, we'll call you."
我认为主要的区别在于框架遵循“好莱坞原则”,即“好莱坞原则”。“别打电话给我们,我们会给你打电话的。”
According to Martin Fowler:
据马丁:
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.
一个框架包含了一些抽象的设计,更多的行为构建在里面。为了使用它,您需要将您的行为插入到框架中的各个位置,要么通过子类化,要么插入到您自己的类中。框架的代码然后在这些点调用您的代码。
#4
186
You call Library.
你叫库。
Framework calls you.
框架调用。
* 助け
足場が痛い
多くの涙*助け足場が痛い多くの涙
#5
181
Library:
It is just a collection of routines (functional programming) or class definitions(object oriented programming). The reason behind is simply code reuse, i.e. get the code that has already been written by other developers. The classes or routines normally define specific operations in a domain specific area. For example, there are some libraries of mathematics which can let developer just call the function without redo the implementation of how an algorithm works.
它只是一个例程(函数式编程)或类定义(面向对象编程)的集合。背后的原因仅仅是代码重用,即获取已经由其他开发人员编写的代码。类或例程通常定义领域特定区域中的特定操作。例如,有一些数学库可以让开发人员在不重做算法工作的情况下调用函数。
Framework:
In framework, all the control flow is already there, and there are a bunch of predefined white spots that we should fill out with our code. A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.
在框架中,所有的控制流都已经存在,并且有一些预定义的白点,我们应该用我们的代码来填充它们。框架通常更复杂。它定义了一个框架,其中应用程序定义了自己的特性来填充骨架。这样,您的代码就会在适当的时候被框架调用。好处是,开发人员不必担心设计是否良好,而仅仅是实现特定于领域的功能。
Library,Framework and your Code image representation:
KeyDifference:
The key difference between a library and a framework is “Inversion of Control”. When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you. Source.
库和框架之间的关键区别是“控制反转”。当您从一个库调用一个方法时,您就处于控制之中。但是在一个框架中,控制是颠倒的:框架调用您。源。
Relation:
Both of them defined API, which is used for programmers to use. To put those together, we can think of a library as a certain function of an application, a framework as the skeleton of the application, and an API is connector to put those together. A typical development process normally starts with a framework, and fill out functions defined in libraries through API.
它们都定义了API,用于程序员使用。要把它们放在一起,我们可以把一个库看作是应用程序的某个功能,一个框架作为应用程序的骨架,一个API是将它们放在一起的连接器。典型的开发过程通常从一个框架开始,并通过API来填写在库中定义的函数。
#6
87
As I've always described it:
正如我一直所描述的:
A Library is a tool.
图书馆是工具。
A Framework is a way of life.
框架是一种生活方式。
A library you can use whatever tiny part helps you. A Framework you must commit your entire project to.
一个图书馆,你可以使用任何微小的部分来帮助你。您必须将整个项目提交给一个框架。
#7
34
I like Cohens answer, but a more technical definition is: Your code calls a library. A framework calls your code. For example a GUI framework calls your code through event-handlers. A web framework calls your code through some request-response model.
我喜欢科恩斯的回答,但更专业的定义是:你的代码调用了一个库。一个框架调用你的代码。例如,GUI框架通过事件处理程序调用您的代码。web框架通过一些请求-响应模型调用您的代码。
This is also called inversion of control - suddenly the framework decides when and how to execute you code rather than the other way around as with libraries. This means that a framework also have a much larger impact on how you have to structure your code.
这也被称为控制反转——突然间,框架决定了何时以及如何执行代码,而不是像使用库那样去执行。这意味着框架对如何构建代码也有更大的影响。
#8
30
From Web developer perspective:
从Web开发人员的角度来看:
-
Library can be easily replaceable by another library. But framework cannot.
图书馆很容易被另一个图书馆取代。但是框架不能。
If you don't like jquery date picker library, you can replace with other date picker such as bootstrap date picker or pickadate.
如果您不喜欢jquery date picker库,可以用其他日期选择器(如bootstrap date picker或pickadate)替换。
If you don't like AngularJS on which you built your product, you cannot just replace with any other frameworks. You have to rewrite your entire code base.
如果您不喜欢构建您的产品的AngularJS,那么您不能仅仅替换其他框架。你必须重写整个代码库。
-
Mostly library takes very less learning curve compared to Frameworks. Eg: underscore.js is a library, Ember.js is a framework.
与框架相比,大多数库的学习曲线要少得多。下划线。js是一个图书馆,Ember。js是一个框架。
#9
21
I forget where I saw this definition, but I think it's pretty nice.
我忘记了我在哪里看到的这个定义,但我认为它很好。
A library is a module that you call from your code, and a framework is a module which calls your code.
库是您从代码中调用的模块,而框架则是调用代码的模块。
#10
9
here is linked a bitter article by Joel Spolsky, but contains a good distinction between toolboxes, libraries, frameworks and such
这里是Joel Spolsky所写的一篇文章,但它包含了工具箱、库、框架等方面的一个很好的区别。
#11
8
This is how I think of it (and have seen rationalized by others):
这就是我对它的看法(也看到了其他人的合理化):
A library is something contained within your code. And a framework is a container for your application.
库是代码中包含的内容。框架是应用程序的容器。
#12
8
A framework can be made out of different libraries. Let's take an example.
一个框架可以由不同的库组成。让我们看一个例子。
Let's say you want to cook a fish curry. Then you need ingredients like oil, spices and other utilities. You also need fish which is your base to prepare your dish on (This is data of your application). all ingredients together called a framework. Now you gonna use them one by one or in combination to make your fish curry which is your final product. Compare that with a web framework which is made out of underscore.js, bootstrap.css, bootstrap.js, fontawesome, AngularJS etc. For an example, Twitter Bootstrap v.35.
比方说你想做咖喱鱼。然后,你需要油、香料和其他实用工具。你也需要鱼,这是你准备菜的基础(这是你的申请数据)。所有的成分都被称为框架。现在你要一个一个地用它们来制作你的鱼咖喱这是你最后的产品。将其与由下划线组成的web框架进行比较。js,引导。css,引导。js, fontawesome, AngularJS等等,举个例子,Twitter Bootstrap v.35。
Now, if you consider only one ingredient, like say oil. You can't use any oil you want because then it will ruin your fish (data). You can only use Olive Oil. Compare that with underscore.js. Now what brand of oil you want to use is up to you. Some dish was made with American Olive Oil (underscore.js) or Indian Olive Oil (lodash.js). This will only change taste of your application. Since they serve almost same purpose, their use depends on the developer's preference and they are easily replaceable.
现在,如果你只考虑一种成分,比如石油。你不能使用任何你想要的油,因为那样会破坏你的鱼(数据)。你只能用橄榄油。这与underscore.js比较。现在你想用什么牌子的油呢?有些菜是用美国橄榄油(underscore.js)或印度橄榄油(lodash.js)制作的。这只会改变应用程序的味道。由于它们的用途几乎相同,它们的使用取决于开发人员的偏好,并且它们很容易被替换。
Framework : A collection of libraries which provide unique properties and behavior to your application. (All ingredients)
框架:为您的应用程序提供独特属性和行为的库的集合。(所有材料)
Library : A well defined set of instructions which provide unique properties and behavior to your data. (Oil on Fish)
库:一套定义良好的指令集,它为您的数据提供独特的属性和行为。(油鱼)
Plugin : A utility build for a library (ui-router -> AngularJS) or many libraries in combination (date-picker -> bootstrap.css + jQuery) without which your plugin might now work as expected.
插件:为一个库(ui-router -> AngularJS)或多个库(date-picker -> bootstrap)构建的实用程序。没有了它,你的插件现在就可以正常工作了。
P.S. AngularJS is a MVC framework but a JavaScript library. Because I believe Library extends default behavior of native technology (JavaScript in this case).
AngularJS是一个MVC框架,但是是一个JavaScript库。因为我认为库扩展了本机技术的默认行为(在本例中是JavaScript)。
#13
5
A library implements functionality for a narrowly-scoped purpose whereas a framework tends to be a collection of libraries providing support for a wider range of features. For example, the library System.Drawing.dll handles drawing functionality, but is only one part of the overall .NET framework.
一个库实现了窄范围目的的功能,而框架则是为更广泛的特性提供支持的库的集合。例如,图书馆系统。dll处理绘图功能,但只是整个. net框架的一部分。
#14
5
Library - Any set of classes or components that can be used as the client deems fit to accomplish a certain task.
Framework - mandates certain guidelines for you to "plug-in" into something bigger than you. You merely provide the pieces specific to your application/requirements in a published-required manner, so that 'the framwework can make your life easy'
库——任何一组类或组件,可作为客户端认为适合完成某项任务。框架——为你的“插件”指定一些指导方针,使之成为比你更大的东西。你只需要以公开的方式提供特定于你的应用程序/需求的部分,这样“framwework可以使你的生活变得轻松”
#15
5
Libraries are for ease of use and efficiency.You can say for example that Zend library helps us accomplish different tasks with its well defined classes and functions.While a framework is something that usually forces a certain way of implementing a solution, like MVC(Model-view-controller)(reference). It is a well-defined system for the distribution of tasks like in MVC.Model contains database side,Views are for UI Interface, and controllers are for Business logic.
图书馆是为了便于使用和提高效率。例如,您可以这样说,Zend library帮助我们使用其定义良好的类和函数来完成不同的任务。虽然框架通常会强制执行某种解决方案,比如MVC(模型-视图-控制器)(引用)。它是一个定义良好的系统,用于在MVC中分配任务。模型包含数据库端,视图用于UI接口,控制器用于业务逻辑。
#16
5
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 sub-classing or by plugging in your own classes. The framework's code then calls your code at these points.
一个框架包含了一些抽象的设计,更多的行为构建在里面。为了使用它,您需要将您的行为插入到框架中的各个位置,要么通过子类化,要么插入到您自己的类中。框架的代码然后在这些点调用您的代码。
#17
4
I think you pinned down quite well the difference: the framework provides a frame in which we do our work... Somehow, it is more "constraining" than a simple library.
The framework is also supposed to add consistency to a set of libraries.
我认为你很好地解决了这个问题:框架提供了我们工作的框架……不知何故,它比简单的库更“约束”。该框架还应该为一组库添加一致性。
#18
4
I think library is a set of utilities to reach a goal (for example, sockets, cryptography, etc). Framework is library + RUNTIME EINVIRONNEMENT. For example, ASP.NET is a framework: it accepts HTTP requests, create page object, invoke lyfe cicle events, etc. Framework does all this, you write a bit of code which will be run at a specific time of the life cycle of current request!
我认为库是一组实现目标的实用工具(例如,套接字、密码学等)。框架是库+运行时的EINVIRONNEMENT。例如,ASP。NET是一个框架:它接受HTTP请求,创建页面对象,调用lyfe cicle事件,等等。框架完成所有这些,您编写了一些代码,这些代码将在当前请求的生命周期的特定时间运行!
Anyway, very interestering question!
不管怎样,非常interestering问题!
#19
4
I don´t remember the source of this answer (I guess I found it in a .ppt in the internet), but the answer is quite simple.
´我不记得这个答案的来源(我猜我发现它在一个ppt在互联网),但答案很简单。
A Library and a Framework are a set of classes, modules and/or code (depending of the programing language) that can be used in your applications and helps you to solve an especific "problem".
一个库和一个框架是一组类、模块和/或代码(依赖于编程语言),可以在应用程序中使用,并帮助您解决一个特殊的“问题”。
That problem can be log or debuging info in an application, draw charts, create an specific file format (html, pdf, xls), connect to a data base, create a part of an application or a complete application or a code applied to a Design Pattern.
这个问题可以在应用程序中记录或调试信息,绘制图表,创建特定的文件格式(html, pdf, xls),连接到数据库,创建应用程序的一部分,或应用于设计模式的完整应用程序或代码。
You can have a Framework or a Library to solve all these problems and many more, normaly the frameworks helps you to solve more complex or bigger problems, but that a consecuence of their main difference, not a main definition for both.
您可以有一个框架或一个库来解决所有这些问题,还有更多的,规范框架帮助您解决更复杂或更大的问题,但这是它们的主要差异的连续,而不是两者的主要定义。
The main difference betwen a Library and a Framework is the dependency betwen their own code, in oder words to use a Framework you need to use almost all the classes, modules or code in the FW, but to use a Library you can use one or few classes, modules or code in the lib in your own application
前后一个图书馆和一个框架的主要区别是依赖在自己的代码中,奥得河就是使用一个框架需要使用几乎所有的类,模块或代码在弗兰克-威廉姆斯,但是使用一个库可以使用一个或几个类,模块或代码的*在您自己的应用程序
This means that if a Framework has, for example has 50 classes in order to use the framework in an app you need to use, let said, 10-15 or more classes in your code, because that is how is designed a Framework, some classes (objects of that classes) are inputs/parameters for methods in other classes in the framework. See the .NET framework, Spring, or any MVC framework.
这意味着,如果一个框架,例如有50个类来使用应用程序需要使用的框架,让说,10 - 15或多个类在代码中,因为这就是设计一个框架,一些类(对象的类)输入/参数方法在其他类的框架。参见。net框架、Spring或任何MVC框架。
But for example a log library, you can just use a Log class in your code, and helps you to solve the "logging problem", that doesn´t mean that the log library doesn't have more classes in his code, like classes to handle files, handle screen outputs, or even data bases, but you never touch/use that classes in your code, and that is the reason of why is a library and not a framework.
但是例如日志库,您可以在代码中使用一个日志类,并帮助你解决“日志问题”,那也´t意味着日志库中没有更多的类代码,像类来处理文件,处理屏幕输出,甚至数据基地,但是你永远不碰/类在代码中使用,这就是为什么一个图书馆的原因,而不是一个框架。
And also there are more categories than Frameworks and Libraries, but that is off topic.
而且还有比框架和库更多的类别,但这不是主题。
#20
3
Your interpretation sounds pretty good to me... A library could be anything that's compiled and self-contained for re-use in other code, there's literally no restriction on its content.
你的解释对我来说很好。一个库可以是任何被编译和独立于其他代码重用的东西,它的内容实际上没有任何限制。
A framework on the other hand is expected to have a range of facilities for use in some specific arena of application development, just like your example, MVC.
另一方面,一个框架预计会有一系列的设施供应用程序开发的特定领域使用,就像您的示例MVC一样。
#1
280
Actually these terms can mean a lot of different things depending the context they are used.
实际上,根据使用的上下文,这些术语可能意味着许多不同的东西。
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.
例如,在Mac OS X框架上,仅仅是库,打包成一个包。在bundle中,您将找到一个实际的动态库(libWhatever.dylib)。裸库和Mac框架的区别在于,一个框架可以包含多个不同版本的库。它可以包含额外的资源(图像、本地化的字符串、XML数据文件、UI对象等),除非框架被公开,它通常包含需要使用库的必要的.h文件。
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).
因此你有一切在一个包需要在应用程序中使用图书馆(C / c++ / objective - C库没有. h文件毫无用处,除非你自己写据库文档),而不是一堆文件移动(Mac包只是一个Unix级别的目录,但UI对待它就像一个单一文件,很像你在Java JAR文件当你点击它时,你通常看不到里面有什么,除非您显式选择显示内容)。
Wikipedia calls framework a "buzzword". It defines a software framework as
*将框架称为“时髦词”。它定义了一个软件框架。
A software framework is a re-usable design for a software system (or subsystem). A software framework may include support programs, code libraries, a scripting language, or other software to help develop and glue together the different components of a software project. Various parts of the framework may be exposed through an API..
软件框架是软件系统(或子系统)的可重用设计。软件框架可能包括支持程序、代码库、脚本语言或其他软件,以帮助开发和粘合软件项目的不同组件。框架的各个部分可以通过API公开。
So I'd say a library is just that, "a library". It is a collection of objects/functions/methods (depending on your language) and your application "links" against it and thus can use the objects/functions/methods. It is basically a file containing re-usable code that can usually be shared among multiple applications (you don't have to write the same code over and over again).
所以我认为图书馆就是一个图书馆。它是对象/函数/方法的集合(取决于您的语言)和您的应用程序“链接”,从而可以使用对象/函数/方法。它基本上是一个包含可重用代码的文件,通常可以在多个应用程序之间共享(您不必一次又一次地编写相同的代码)。
A framework can be everything you use in application development. It can be a library, a collection of many libraries, a collection of scripts, or any piece of software you need to create your application. Framework is just a very vague term.
框架可以是应用程序开发中使用的所有内容。它可以是一个库、许多库的集合、一个脚本集合,或者任何需要创建应用程序的软件。框架只是一个非常模糊的术语。
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.
这里有一篇关于“图书馆与框架”主题的文章。我个人认为这篇文章是很有争议的。不过,他说的并不是错误的,他只是挑出了一个框架的多重定义,并将其与经典的库定义进行比较。他说你需要一个子类化的框架。真的吗?我可以在一个库中定义一个对象,我可以链接它,并在我的代码中对它进行子类化。我不认为我需要一个“框架”。在某种程度上,他解释了术语框架是如何被使用的。就像我之前说的,这只是一个炒作的词。有些公司只发布一个普通的库(在任何意义上都是经典的库),并称之为“框架”,因为它听起来更花哨。
#2
415
A library performs specific, well-defined operations.
一个库执行特定的、定义良好的操作。
A framework is a skeleton where the application defines the "meat" of the operation by filling out the skeleton. The skeleton still has code to link up the parts but the most important work is done by the application.
框架是一个框架,应用程序通过填充骨架来定义操作的“肉”。骨架仍然有代码来连接部分,但是最重要的工作是由应用程序完成的。
Examples of libraries: Network protocols, compression, image manipulation, string utilities, regular expression evaluation, math. Operations are self-contained.
库的例子:网络协议、压缩、图像处理、字符串实用程序、正则表达式计算、数学。操作都是独立的。
Examples of frameworks: Web application system, Plug-in manager, GUI system. The framework defines the concept but the application defines the fundamental functionality that end-users care about.
框架示例:Web应用程序系统、插件管理器、GUI系统。框架定义了概念,但是应用程序定义了最终用户关心的基本功能。
#3
233
I think that the main difference is that frameworks follow the "Hollywood principle", i.e. "don't call us, we'll call you."
我认为主要的区别在于框架遵循“好莱坞原则”,即“好莱坞原则”。“别打电话给我们,我们会给你打电话的。”
According to Martin Fowler:
据马丁:
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.
一个框架包含了一些抽象的设计,更多的行为构建在里面。为了使用它,您需要将您的行为插入到框架中的各个位置,要么通过子类化,要么插入到您自己的类中。框架的代码然后在这些点调用您的代码。
#4
186
You call Library.
你叫库。
Framework calls you.
框架调用。
* 助け
足場が痛い
多くの涙*助け足場が痛い多くの涙
#5
181
Library:
It is just a collection of routines (functional programming) or class definitions(object oriented programming). The reason behind is simply code reuse, i.e. get the code that has already been written by other developers. The classes or routines normally define specific operations in a domain specific area. For example, there are some libraries of mathematics which can let developer just call the function without redo the implementation of how an algorithm works.
它只是一个例程(函数式编程)或类定义(面向对象编程)的集合。背后的原因仅仅是代码重用,即获取已经由其他开发人员编写的代码。类或例程通常定义领域特定区域中的特定操作。例如,有一些数学库可以让开发人员在不重做算法工作的情况下调用函数。
Framework:
In framework, all the control flow is already there, and there are a bunch of predefined white spots that we should fill out with our code. A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.
在框架中,所有的控制流都已经存在,并且有一些预定义的白点,我们应该用我们的代码来填充它们。框架通常更复杂。它定义了一个框架,其中应用程序定义了自己的特性来填充骨架。这样,您的代码就会在适当的时候被框架调用。好处是,开发人员不必担心设计是否良好,而仅仅是实现特定于领域的功能。
Library,Framework and your Code image representation:
KeyDifference:
The key difference between a library and a framework is “Inversion of Control”. When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you. Source.
库和框架之间的关键区别是“控制反转”。当您从一个库调用一个方法时,您就处于控制之中。但是在一个框架中,控制是颠倒的:框架调用您。源。
Relation:
Both of them defined API, which is used for programmers to use. To put those together, we can think of a library as a certain function of an application, a framework as the skeleton of the application, and an API is connector to put those together. A typical development process normally starts with a framework, and fill out functions defined in libraries through API.
它们都定义了API,用于程序员使用。要把它们放在一起,我们可以把一个库看作是应用程序的某个功能,一个框架作为应用程序的骨架,一个API是将它们放在一起的连接器。典型的开发过程通常从一个框架开始,并通过API来填写在库中定义的函数。
#6
87
As I've always described it:
正如我一直所描述的:
A Library is a tool.
图书馆是工具。
A Framework is a way of life.
框架是一种生活方式。
A library you can use whatever tiny part helps you. A Framework you must commit your entire project to.
一个图书馆,你可以使用任何微小的部分来帮助你。您必须将整个项目提交给一个框架。
#7
34
I like Cohens answer, but a more technical definition is: Your code calls a library. A framework calls your code. For example a GUI framework calls your code through event-handlers. A web framework calls your code through some request-response model.
我喜欢科恩斯的回答,但更专业的定义是:你的代码调用了一个库。一个框架调用你的代码。例如,GUI框架通过事件处理程序调用您的代码。web框架通过一些请求-响应模型调用您的代码。
This is also called inversion of control - suddenly the framework decides when and how to execute you code rather than the other way around as with libraries. This means that a framework also have a much larger impact on how you have to structure your code.
这也被称为控制反转——突然间,框架决定了何时以及如何执行代码,而不是像使用库那样去执行。这意味着框架对如何构建代码也有更大的影响。
#8
30
From Web developer perspective:
从Web开发人员的角度来看:
-
Library can be easily replaceable by another library. But framework cannot.
图书馆很容易被另一个图书馆取代。但是框架不能。
If you don't like jquery date picker library, you can replace with other date picker such as bootstrap date picker or pickadate.
如果您不喜欢jquery date picker库,可以用其他日期选择器(如bootstrap date picker或pickadate)替换。
If you don't like AngularJS on which you built your product, you cannot just replace with any other frameworks. You have to rewrite your entire code base.
如果您不喜欢构建您的产品的AngularJS,那么您不能仅仅替换其他框架。你必须重写整个代码库。
-
Mostly library takes very less learning curve compared to Frameworks. Eg: underscore.js is a library, Ember.js is a framework.
与框架相比,大多数库的学习曲线要少得多。下划线。js是一个图书馆,Ember。js是一个框架。
#9
21
I forget where I saw this definition, but I think it's pretty nice.
我忘记了我在哪里看到的这个定义,但我认为它很好。
A library is a module that you call from your code, and a framework is a module which calls your code.
库是您从代码中调用的模块,而框架则是调用代码的模块。
#10
9
here is linked a bitter article by Joel Spolsky, but contains a good distinction between toolboxes, libraries, frameworks and such
这里是Joel Spolsky所写的一篇文章,但它包含了工具箱、库、框架等方面的一个很好的区别。
#11
8
This is how I think of it (and have seen rationalized by others):
这就是我对它的看法(也看到了其他人的合理化):
A library is something contained within your code. And a framework is a container for your application.
库是代码中包含的内容。框架是应用程序的容器。
#12
8
A framework can be made out of different libraries. Let's take an example.
一个框架可以由不同的库组成。让我们看一个例子。
Let's say you want to cook a fish curry. Then you need ingredients like oil, spices and other utilities. You also need fish which is your base to prepare your dish on (This is data of your application). all ingredients together called a framework. Now you gonna use them one by one or in combination to make your fish curry which is your final product. Compare that with a web framework which is made out of underscore.js, bootstrap.css, bootstrap.js, fontawesome, AngularJS etc. For an example, Twitter Bootstrap v.35.
比方说你想做咖喱鱼。然后,你需要油、香料和其他实用工具。你也需要鱼,这是你准备菜的基础(这是你的申请数据)。所有的成分都被称为框架。现在你要一个一个地用它们来制作你的鱼咖喱这是你最后的产品。将其与由下划线组成的web框架进行比较。js,引导。css,引导。js, fontawesome, AngularJS等等,举个例子,Twitter Bootstrap v.35。
Now, if you consider only one ingredient, like say oil. You can't use any oil you want because then it will ruin your fish (data). You can only use Olive Oil. Compare that with underscore.js. Now what brand of oil you want to use is up to you. Some dish was made with American Olive Oil (underscore.js) or Indian Olive Oil (lodash.js). This will only change taste of your application. Since they serve almost same purpose, their use depends on the developer's preference and they are easily replaceable.
现在,如果你只考虑一种成分,比如石油。你不能使用任何你想要的油,因为那样会破坏你的鱼(数据)。你只能用橄榄油。这与underscore.js比较。现在你想用什么牌子的油呢?有些菜是用美国橄榄油(underscore.js)或印度橄榄油(lodash.js)制作的。这只会改变应用程序的味道。由于它们的用途几乎相同,它们的使用取决于开发人员的偏好,并且它们很容易被替换。
Framework : A collection of libraries which provide unique properties and behavior to your application. (All ingredients)
框架:为您的应用程序提供独特属性和行为的库的集合。(所有材料)
Library : A well defined set of instructions which provide unique properties and behavior to your data. (Oil on Fish)
库:一套定义良好的指令集,它为您的数据提供独特的属性和行为。(油鱼)
Plugin : A utility build for a library (ui-router -> AngularJS) or many libraries in combination (date-picker -> bootstrap.css + jQuery) without which your plugin might now work as expected.
插件:为一个库(ui-router -> AngularJS)或多个库(date-picker -> bootstrap)构建的实用程序。没有了它,你的插件现在就可以正常工作了。
P.S. AngularJS is a MVC framework but a JavaScript library. Because I believe Library extends default behavior of native technology (JavaScript in this case).
AngularJS是一个MVC框架,但是是一个JavaScript库。因为我认为库扩展了本机技术的默认行为(在本例中是JavaScript)。
#13
5
A library implements functionality for a narrowly-scoped purpose whereas a framework tends to be a collection of libraries providing support for a wider range of features. For example, the library System.Drawing.dll handles drawing functionality, but is only one part of the overall .NET framework.
一个库实现了窄范围目的的功能,而框架则是为更广泛的特性提供支持的库的集合。例如,图书馆系统。dll处理绘图功能,但只是整个. net框架的一部分。
#14
5
Library - Any set of classes or components that can be used as the client deems fit to accomplish a certain task.
Framework - mandates certain guidelines for you to "plug-in" into something bigger than you. You merely provide the pieces specific to your application/requirements in a published-required manner, so that 'the framwework can make your life easy'
库——任何一组类或组件,可作为客户端认为适合完成某项任务。框架——为你的“插件”指定一些指导方针,使之成为比你更大的东西。你只需要以公开的方式提供特定于你的应用程序/需求的部分,这样“framwework可以使你的生活变得轻松”
#15
5
Libraries are for ease of use and efficiency.You can say for example that Zend library helps us accomplish different tasks with its well defined classes and functions.While a framework is something that usually forces a certain way of implementing a solution, like MVC(Model-view-controller)(reference). It is a well-defined system for the distribution of tasks like in MVC.Model contains database side,Views are for UI Interface, and controllers are for Business logic.
图书馆是为了便于使用和提高效率。例如,您可以这样说,Zend library帮助我们使用其定义良好的类和函数来完成不同的任务。虽然框架通常会强制执行某种解决方案,比如MVC(模型-视图-控制器)(引用)。它是一个定义良好的系统,用于在MVC中分配任务。模型包含数据库端,视图用于UI接口,控制器用于业务逻辑。
#16
5
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 sub-classing or by plugging in your own classes. The framework's code then calls your code at these points.
一个框架包含了一些抽象的设计,更多的行为构建在里面。为了使用它,您需要将您的行为插入到框架中的各个位置,要么通过子类化,要么插入到您自己的类中。框架的代码然后在这些点调用您的代码。
#17
4
I think you pinned down quite well the difference: the framework provides a frame in which we do our work... Somehow, it is more "constraining" than a simple library.
The framework is also supposed to add consistency to a set of libraries.
我认为你很好地解决了这个问题:框架提供了我们工作的框架……不知何故,它比简单的库更“约束”。该框架还应该为一组库添加一致性。
#18
4
I think library is a set of utilities to reach a goal (for example, sockets, cryptography, etc). Framework is library + RUNTIME EINVIRONNEMENT. For example, ASP.NET is a framework: it accepts HTTP requests, create page object, invoke lyfe cicle events, etc. Framework does all this, you write a bit of code which will be run at a specific time of the life cycle of current request!
我认为库是一组实现目标的实用工具(例如,套接字、密码学等)。框架是库+运行时的EINVIRONNEMENT。例如,ASP。NET是一个框架:它接受HTTP请求,创建页面对象,调用lyfe cicle事件,等等。框架完成所有这些,您编写了一些代码,这些代码将在当前请求的生命周期的特定时间运行!
Anyway, very interestering question!
不管怎样,非常interestering问题!
#19
4
I don´t remember the source of this answer (I guess I found it in a .ppt in the internet), but the answer is quite simple.
´我不记得这个答案的来源(我猜我发现它在一个ppt在互联网),但答案很简单。
A Library and a Framework are a set of classes, modules and/or code (depending of the programing language) that can be used in your applications and helps you to solve an especific "problem".
一个库和一个框架是一组类、模块和/或代码(依赖于编程语言),可以在应用程序中使用,并帮助您解决一个特殊的“问题”。
That problem can be log or debuging info in an application, draw charts, create an specific file format (html, pdf, xls), connect to a data base, create a part of an application or a complete application or a code applied to a Design Pattern.
这个问题可以在应用程序中记录或调试信息,绘制图表,创建特定的文件格式(html, pdf, xls),连接到数据库,创建应用程序的一部分,或应用于设计模式的完整应用程序或代码。
You can have a Framework or a Library to solve all these problems and many more, normaly the frameworks helps you to solve more complex or bigger problems, but that a consecuence of their main difference, not a main definition for both.
您可以有一个框架或一个库来解决所有这些问题,还有更多的,规范框架帮助您解决更复杂或更大的问题,但这是它们的主要差异的连续,而不是两者的主要定义。
The main difference betwen a Library and a Framework is the dependency betwen their own code, in oder words to use a Framework you need to use almost all the classes, modules or code in the FW, but to use a Library you can use one or few classes, modules or code in the lib in your own application
前后一个图书馆和一个框架的主要区别是依赖在自己的代码中,奥得河就是使用一个框架需要使用几乎所有的类,模块或代码在弗兰克-威廉姆斯,但是使用一个库可以使用一个或几个类,模块或代码的*在您自己的应用程序
This means that if a Framework has, for example has 50 classes in order to use the framework in an app you need to use, let said, 10-15 or more classes in your code, because that is how is designed a Framework, some classes (objects of that classes) are inputs/parameters for methods in other classes in the framework. See the .NET framework, Spring, or any MVC framework.
这意味着,如果一个框架,例如有50个类来使用应用程序需要使用的框架,让说,10 - 15或多个类在代码中,因为这就是设计一个框架,一些类(对象的类)输入/参数方法在其他类的框架。参见。net框架、Spring或任何MVC框架。
But for example a log library, you can just use a Log class in your code, and helps you to solve the "logging problem", that doesn´t mean that the log library doesn't have more classes in his code, like classes to handle files, handle screen outputs, or even data bases, but you never touch/use that classes in your code, and that is the reason of why is a library and not a framework.
但是例如日志库,您可以在代码中使用一个日志类,并帮助你解决“日志问题”,那也´t意味着日志库中没有更多的类代码,像类来处理文件,处理屏幕输出,甚至数据基地,但是你永远不碰/类在代码中使用,这就是为什么一个图书馆的原因,而不是一个框架。
And also there are more categories than Frameworks and Libraries, but that is off topic.
而且还有比框架和库更多的类别,但这不是主题。
#20
3
Your interpretation sounds pretty good to me... A library could be anything that's compiled and self-contained for re-use in other code, there's literally no restriction on its content.
你的解释对我来说很好。一个库可以是任何被编译和独立于其他代码重用的东西,它的内容实际上没有任何限制。
A framework on the other hand is expected to have a range of facilities for use in some specific arena of application development, just like your example, MVC.
另一方面,一个框架预计会有一系列的设施供应用程序开发的特定领域使用,就像您的示例MVC一样。