简体   繁体   English

“包装”和“模块”之间有什么区别?

[英]What's the difference between “package” and “module”?

I use Java where we only have packages. 我在只有软件包的地方使用Java。 I know there are other programming languages that also include modules. 我知道还有其他编程语言也包含模块。

What's the difference? 有什么不同?

It's hard to compare semantics in the void. 很难比较空白中的语义。 (What other languages do you mean?) A "module" might be analogous to a Java class, or a Java package, or something else entirely, depending on that other language. (您还说什么其他语言?)“模块”可能类似于Java类,Java包或完全其他的东西,具体取决于该其他语言。 Typically since "modules" tend to be from procedural languages, I'd lean toward saying Java class, but I think the line is very fuzzy at that point and you could argue package quite convincingly. 通常,由于“模块”通常来自过程语言,因此我倾向于讲Java类,但是我认为那一线模糊,可以令人信服地争论一下程序包。

instanceofTom's comment nailed it - Different languages have different definitions of package and module. instanceofTom的评论已将其钉牢-不同的语言对包和模块的定义不同。 Therefore there's no language agnostic answer to this question. 因此,这个问题没有语言不可知的答案。

I'll try to answer it from the perspective of some of the languages I know: 我将尝试从我所知道的一些语言的角度回答这个问题:

  • Java: It has a concept of package s, which are basically just a mechanism for organizing Java classes, interfaces etc into namespaces. Java:它具有package的概念,基本上就是将Java类,接口等组织到名称空间中的一种机制。 They require hierarchical structure. 他们需要层次结构。 package s don't have first class status. package没有头等舱状态。 It might also be worth noting that superpackage s proposed for Java 7 are also sometimes referred to as module s. 值得注意的是,为Java 7提议的superpackage有时也称为module

  • Modula: module s, same in concept to Java's package s. modulemodule ,在概念上与Java的package相同。 Don't require hierarchical structure. 不需要层次结构。

  • C#: namespaces , same in concept to Java's package s. C#: namespaces ,在概念上与Java的package相同。 Don't require hierarchical structure. 不需要层次结构。

  • C++: namespaces , As the name indicates, these are just namespaces. C ++: namespaces ,顾名思义,它们只是名称空间。 Don't require hierarchical structure. 不需要层次结构。

  • Haskell: module s, same in concept to Java's package s. Haskell: module ,在概念上与Java的package相同。

  • Scala: package s in Scala are same as package s in Java, except that they don't require hierarchical structures. 斯卡拉: package S IN斯卡拉是一样package在Java中S,只是他们不需要层次结构。 A few more restrictions like one-public-class-per-file have also been relaxed. 还放宽了一些限制,例如每个文件一个公共类。 object s in Scala are also referred to as modules, and they also enjoy the first-class status. Scala中的object s也称为模块,它们也享有一流的地位。

  • F#: namespaces in F# are same as C# namespace s. F#:F#中的namespaces与C# namespace相同。 Besides namespace s, F# also has modules which are implemented at CLR level as .NET classes with static methods. 除了namespace之外,F#还具有在CLR级别以静态方法作为.NET类实现的modules They aren't first-class entities. 他们不是一流的实体。

Java Platform Module System or JPMS was introduced when was released. 发布时引入了Java平台模块系统或JPMS。 Starting from that time Java has both packages and modules . 从那时起,Java同时拥有packagesmodules So what is the difference between them? 那么它们之间有什么区别呢?

What is a Package? 什么是包裹?

A package is a namespace that organizes a set of related classes and interfaces. 包是一个命名空间,用于组织一组相关的类和接口。

What is a Module? 什么是模块?

A module is a collection of related Java packages and associated resources with a descriptor file, which contains information about which packages/resources are exposed by this module, which packages are used by current module and some other information. 模块是相关Java软件包和带有描述符文件的关联资源的集合,该描述符文件包含有关此模块公开哪些软件包/资源,当前模块使用哪些软件包以及其他一些信息的信息。

We can thing of a Java Module as a higher level of aggregation above packages. 我们可以将Java模块看作是软件包之上的更高级别的聚合。 A Module allows you to organize a few packages into one single logical unit and to distribute them as one whole system. 模块使您可以将几个软件包组织到一个逻辑单元中,并将它们作为一个完整的系统进行分发。 As well JPMS provides a way to control which packages are visible to users. JPMS还提供了一种控制哪些软件包对用户可见的方法。

It seems that, as other answers state, the notion of module varies from one language to another, some even not having it (but a corresponding counterpart). 似乎,正如其他答案所言,模块的概念从一种语言到另一种语言是变化的,有些甚至不具有(但是是对应的对应语言)。

However, it seems that nowadays modules is more a concept and refers to a set of source code files that can be shared independently. 但是,如今的模块似乎已成为一个概念,它指的是一组可以独立共享的源代码文件。 Following this definition, Java jar files are not modules as they contain bytecode compiled files (.class files). 按照此定义,Java jar文件不是模块,因为它们包含字节码编译文件(.class文件)。 A module system complying with this definition is to be introduced in Java 9 ( see this article ) and is present in other languages that have module or package managers, often directly naming modules packages (Go lang/go tool, Python/pip, PHP/Composer...) where package generally are packed modules. 符合此定义的模块系统将在Java 9中引入( 请参阅本文 ),并以其他具有模块或包管理器的语言提供,通常直接命名模块 (Go lang / go工具,Python / pip,PHP / Composer ...),其中包装通常是包装好的模块。

A package is more akin to a C++ namespace than a module. 包与模块更像是C ++名称空间。 A module is more akin to an enclosing class than to a package. 模块与封装类更像是一个封闭的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jar包和class包之间有什么区别? - What's the difference between package with jar and package with classes? AccessLevel.PACKAGE 和 AccessLevel.MODULE 有什么区别? - What is the difference between AccessLevel.PACKAGE and AccessLevel.MODULE? 需求和模块声明中需要静态之间的区别是什么 - What's the difference between requires and requires static in module declaration elasticsearch插件和elasticsearch模块之间有什么区别? - What's the difference between elasticsearch plugin and elasticsearch module? #{} $ {}和%{}之间有什么区别? - what's the difference between #{} ${} and %{}? ResolvedModule,Module和Observable Module之间有什么区别 - What is the difference between ResolvedModule, Module and Observable Module OSGi:Import-Package / Export-Package和Require-Capability / Provide Capability之间有什么区别? - OSGi: What's the difference between Import-Package/Export-Package and Require-Capability/Provide Capability? Java 6的Rhino内置版本和Mozilla直接使用的Rhino软件包有什么区别? - What's the difference between Java 6's built-in version of Rhino and the Rhino package direct from Mozilla? 这两个ifs有什么区别? - What's the difference between these 2 ifs? 库、存储库、包和文件夹之间有什么区别? - What is the difference between a library, respository, package and folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM