模块,库和框架之间的区别 [英] Difference between a module, library and a framework

查看:494
本文介绍了模块,库和框架之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用流行的编程语言来说,这些术语之间有什么区别,什么是重叠部分?

我错过了任何相关条款吗?

解决方案

所有这三个功能都提供.

但是,有一些重要的区别.

只是 相关功能的集合.仅此而已,也不过如此.库的定义特征是 you 受控制, you 调用该库.

框架的定义特征是控制反转.该框架调用 you ,而不是相反. (这就是好莱坞原则:不要打电话给我们,我们会打电话给您.")框架处于控制之中.控制流和数据流由框架管理.

您可以这样考虑:在两种情况下,您都有一个应用程序,并且此应用程序中存在漏洞,其中已遗漏了代码,并且需要填补这些漏洞.库和框架是

  • 编写应用程序的人
  • 什么是孔和
  • 填补空缺的人.

使用库,编写应用程序,然后省去无聊的详细信息,这些详细信息由填充. /p>

使用框架,框架编写器编写应用程序,并保留有趣的详细信息,您只需填写 .

有时这可能会造成一些混乱,因为框架本身可能还包含无聊的细节,框架作者填充了库,您编写的部分可能包含了无聊的细节,您填充了库,并且框架可能会提供一组捆绑的库,这些库可以与框架很好地结合使用,或者经常需要与框架结合使用.例如,当您使用Web框架编写Web应用程序时,可能会使用XML生成器库,而该XML库可能是该框架提供的,甚至可能是该框架的组成部分.

但是,这并不意味着库与框架之间没有区别.区别非常清楚:控制反转就是它的全部.

模块的定义特征是信息隐藏.模块具有一个 interface ,该接口显式地抽象地指定其提供的功能以及所依赖的功能. (通常称为 exported imported 功能.)此接口具有实现(实际上是多个实现),该接口从用户的一个模块是一个黑匣子.

此外,库是相关功能的集合,而模块仅提供单个功能.这意味着,如果您的系统同时具有模块和库,则一个库通常将包含多个模块.例如,您可能有一个集合库,其中包含一个List模块,一个Set模块和一个Map模块.

尽管您当然可以在不使用模块系统的情况下编写模块,但理想情况下,您希望模块可以单独编译(对于该概念甚至有意义的语言和执行环境),可以分别部署,并且希望模块组成是安全的(即组成模块应该在运行前起作用或触发错误,但决不会导致运行时错误或意外行为.为此,您需要一个模块系统,例如Racket的单元,Standard ML的模块和函子或Newspeak的顶级类.

所以,让我们回顾一下:

  • :相关功能的集合
  • 框架:控制反转
  • 模块:具有显式导出和导入的抽象接口,实现和接口是分开的,可能有多个实现,并且实现是隐藏的

In popular programming speak, what is the difference between these terms and what are the overlaps?

Any related terms I'm missing out?

解决方案

All three of those provide functionality.

However, there are important differences.

A library is just a collection of related functionality. Nothing more, but also nothing less. The defining characteristic of a library is that you are in control, you call the library.

The defining characteristic of a framework is Inversion of Control. The framework calls you, not the other way round. (This is known as the Hollywood Principle: "Don't call us, we'll call you.") The framework is in control. The flow of control and the flow of data is managed by the framework.

You can think of it this way: in both cases, you have an application, and this application has holes in it, where code has been left out, and these holes need to be filled in. The difference between a library and a framework is

  • who writes the application,
  • what are the holes and
  • who fills in the holes.

With a library, you write the application, and you leave out the boring details, which gets filled in by a library.

With a framework, the framework writer writes the application, and leaves out the interesting details, which you fill in.

This can be a little confusing at times, because the framework itself might also contain boring details, that the framework author filled in with libraries, the parts that you write might contain boring details, that you fill in with libraries, and the framework might provide a set of bundled libraries that either work well with the framework or that are often needed in conjunction with the framework. For example, you might use an XML generator library when writing a web application using a web framework, and that XML library might have been provided by the framework or even be an integral part of it.

That doesn't mean, however, that there is no distinction between a library and a framework. The distinction is very clear: Inversion of Control is what it's all about.

The defining characteristic of a module is information hiding. A module has an interface, which explicitly, but abstractly specifies both the functionality it provides as well as the functionality it depends on. (Often called the exported and imported functionality.) This interface has an implementation (or multiple implementations, actually), which, from the user of a module are a black box.

Also, a library is a collection of related functionality, whereas a module only provides a single piece of functionality. Which means that, if you have a system with both modules and libraries, a library will typically contain multiple modules. For example, you might have a collections library which contains a List module, a Set module and a Map module.

While you can certainly write modules without a module system, ideally you want your modules to be separately compilable (for languages and execution environments where that notion even makes sense), separately deployable, and you want module composition to be safe (i.e. composing modules should either work or trigger an error before runtime, but never lead to an runtime error or unexpected behavior). For this, you need a module system, like Racket's units, Standard ML's modules and functors or Newspeak's top-level classes.

So, let's recap:

  • library: collection of related functionality
  • framework: Inversion of Control
  • module: abstract interface with explicit exports and imports, implementation and interface are separate, there may be multiple implementations and the implementation is hidden

这篇关于模块,库和框架之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆