框架和库之间的区别是什么?
我一直认为库是一组对象和函数,专注于解决特定的问题或应用程序开发的特定领域(即数据库访问);另一方面,框架是一个以特定方法论(即MVC)为中心的库的集合,它涵盖了应用程序开发的所有领域。
框架和库之间的区别是什么?
我一直认为库是一组对象和函数,专注于解决特定的问题或应用程序开发的特定领域(即数据库访问);另一方面,框架是一个以特定方法论(即MVC)为中心的库的集合,它涵盖了应用程序开发的所有领域。
当前回答
一个框架可以由不同的库组成。让我们举个例子。
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.
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 the taste of your application. Since they serve almost the same purpose, their use depends on the developer's preference and they are easily replaceable.
框架:为应用程序提供独特属性和行为的库的集合。(所有材料) 库:一组定义良好的指令,为数据提供独特的属性和行为。(鱼身上的油) 插件:一个库(ui-router -> AngularJS)或多个库的组合(date-picker -> bootstrap.css + jQuery)的工具构建,如果没有它,你的插件现在可能会正常工作。
P.S. AngularJS是一个MVC框架,但却是一个JavaScript库。因为我相信Library扩展了本地技术(在这里是JavaScript)的默认行为。
其他回答
库执行特定的、定义良好的操作。
框架是一个骨架,应用程序通过填充骨架来定义操作的“肉”。框架仍然有代码来连接各个部分,但最重要的工作是由应用程序完成的。
库的例子:网络协议、压缩、图像处理、字符串实用程序、正则表达式计算、数学。操作是独立的。
框架示例:Web应用程序系统,插件管理器,GUI系统。框架定义概念,而应用程序定义最终用户关心的基本功能。
你的解释听起来不错。库可以是任何经过编译和自包含的东西,以便在其他代码中重用,实际上对其内容没有任何限制。
另一方面,框架应该具有一系列用于应用程序开发的特定领域的功能,就像您的示例MVC一样。
库vs框架
Martin Fowler - InversionOfControl
库和框架是你的代码的外部代码。它可以是文件(例如。jar),系统代码(操作系统的一部分)等。
库是一组有用的代码。主要关注你的代码。库解决的任务范围很窄。例如,实用程序,排序,模块化
your code ->(has) Library API
框架或控制反转(IoC)容器[About]是更多的东西。框架解决了广泛的任务(特定于领域),你委派这个任务给框架。IoC——你的代码依赖于框架逻辑、事件…因此框架会调用你的代码。它迫使你的代码坚持它的规则(实现/扩展协议/接口/契约),传递lambdas…例如-测试,GUI, DI框架…
your code ->(has) and ->(implements) Framework API
[iOS Library vs Framework]
[DIP vs DI vs IoC]
根据Erich Gamma等人在《设计模式》一书中给出的定义:
库:构成可重用实现的一组相关过程和类; 框架:由一组具有模板方法的协作类组成的可重用规范。它设置了控制流,并允许通过在子类中重写框架类中模板方法调用的钩子方法来将框架裁剪到特定问题的流中。
特定于问题的代码可以使用库和实现框架。
一个框架可以由不同的库组成。让我们举个例子。
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.
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 the taste of your application. Since they serve almost the same purpose, their use depends on the developer's preference and they are easily replaceable.
框架:为应用程序提供独特属性和行为的库的集合。(所有材料) 库:一组定义良好的指令,为数据提供独特的属性和行为。(鱼身上的油) 插件:一个库(ui-router -> AngularJS)或多个库的组合(date-picker -> bootstrap.css + jQuery)的工具构建,如果没有它,你的插件现在可能会正常工作。
P.S. AngularJS是一个MVC框架,但却是一个JavaScript库。因为我相信Library扩展了本地技术(在这里是JavaScript)的默认行为。