必须使用什么 UML 元素才能在 class 图上显示 JPMS 模块?

What UML element must be used to show JPMS module on class diagram?

我试图在我的 UML class 图表上显示两个 JPMS 模块以及它们内部的包和 classes。问题是我无法理解使用什么元素来显示模块。请帮忙。

我认为你必须使用一个包来表示 JPMS 模块,也许用“JPMS 模块”或其他东西来刻板化它以增加更多含义。这听起来不像 JPMS 模块是 class 或接口等。所以我不认为你可以从 UML Class 模型中使用其他任何东西来表示它。

这取决于你想如何设计你的系统。当您将 JMPS 模块视为具有已定义接口的封闭元素时,组件就是正确的模型元素。即,您应用封装原则。如果您将它们视为仅包含一些元素的容器,并且您想直接使用这些内部元素,那么包就是正确的元素。

在 UML 中:

组件

:见reference 1

Package is a namespace used to group together elements that are semantically related and might change together. It is a general purpose mechanism to organize elements into groups to provide better structure for system model.

reference 2中:

Pretty much all UML elements can be grouped into packages. Thus, classes, objects, use cases, components, nodes, node instances etc. can all be organized as packages, thus enabling a manageable organization of the myriad elements that a real-world UML model entails.

组件:参见reference 3

A component is a class representing a modular part of a system with encapsulated content and whose manifestation is replaceable within its environment.

A component has its behavior defined in terms of provided interfaces and required interfaces (potentially exposed via ports).

Component serves as a type whose conformance is defined by these provided and required interfaces (encompassing both their static as well as dynamic semantics). One component may therefore be substituted by another only if the two are type conformant.


在Java9:

参考:书籍:Java 9 Modularity Revealed,Alexandru Jecan,2017 年,第 5 页

模块的特征

Some of the characteristics of a module include the following:

  • A module must define interfaces for communication with other modules.
  • A module defines a separation between the module interface and the module implementation.
  • A module should present a set of properties that contain information.
  • Two or more modules can be nested together.
  • A module should have a clear, defined responsibility. Each function should be implemented by only one module.
  • A module must be able to be tested independently from other modules.
  • An error in a module should not propagate to other modules.


因此:
Java 9 个 JPMS 模块应由 UML 组件显示。我们不能使用 UML 包来建模 Java 9 模块。 UML 包用于建模 Java 包。众所周知,Java 9 个包和模块之间存在巨大差异。