组件图是否仅指物理组件?

Do Component diagrams refer to physical components only?

在 UML 组件图中,是否可以很好地测试某物是否符合 "component" 条件,它是物理隔离的吗?

我发现的大多数定义(维基百科、TutorialsPoints 等)都将组件称为 "files, libraries, executables, etc."

但是,一些插图(参见 "Creating Component Diagrams" 标题下的 http://agilemodeling.com/artifacts/componentDiagram.htm) seem to model classes as components (e.g. "Student," "Seminar") which at first glance might give the indication that these are just some important classes in the application. However, reading further down,其中大量引用了 "network traffic" ("reduce the potential network traffic");这意味着建模的组件是通过网络端口进行通信的不同进程或可执行文件。这似乎意味着实例在同一个 JVM 中的个体 类(我可能会添加相同的物理 .jar)应该在同一个组件中UML 组件图。这总是正确的吗?如果不是,那么在同一 jar 和同一 JVM 中的 object 个实例在该图中何时会被视为不同的组件?

不,UML 组件不限于 物理 文件或类似文件。

Physical 甚至可能不是谈论系统上文件的好术语,因为您无法真正触摸文件。都是比特和字节。

UML 2.5 将组件定义为

A Component represents a modular part of a system that encapsulates its contents and whose manifestation is replaceable within its environment.

此外它说

A Component is a self-contained unit that encapsulates the state and behavior of a number of Classifiers. A Component specifies a formal contract of the services that it provides to its clients and those that it requires from other Components or services in the system in terms of its provided and required Interfaces.

A Component is a substitutable unit that can be replaced at design time or run-time by a Component that offers equivalent functionality based on compatibility of its Interfaces. As long as the environment is fully compatible with the provided and required Interfaces of a Component, it will be able to interact with this environment. Similarly, a system can be extended by adding new Component types that add new functionality. Larger pieces of a system’s functionality may be assembled by reusing Components as parts in an encompassing Component or assembly of Components, and wiring them together.

因此 SkypeChrome 等软件应用程序可以建模为组件,但也可以建模为内部部件聊天引擎HTML渲染器可以被认为是组件。

通常在 物理 实现中实际上反映了组件结构;一个软件的每个组件都可以编译成一个 dll

除了 Geert 的出色回答之外,当您不一定总是需要它时,将通常看起来像 class 的东西与与之相关的所有东西封装为一个组件通常是个好主意。

想象一个可以管理公司车队的应用程序。通常它会附带对汽车的支持。然而,您可能希望能够添加额外的组件,以便能够处理飞机、轮船或自行车。在这种情况下,您也可能不需要汽车。这些东西中的每一个都将成为组件,即使您可以将它简单地建模为唯一 class 的子 class ,它驻留在名为 Vehicle 的系统核心中。例如,您可能有与那些自行车相关的不同元素,这些元素未包含在 class 本身中。考虑屏幕、维护模型以及与只能应用于 sub-class 级别的不同方法相关的所有内容会有何不同。

此类系统中组件的其他示例可以是 Drivers。这不再是 Vehicle 的 sub-class,而是一些与 Vehicles 交互的独立 class。同样,根据情况,您可能只对公司中的汽车感兴趣,或者将它们链接到分配给它们甚至允许使用它们的 Drivers。因此,你想出了一组完全不同的依赖项、屏幕、方法等,它们不仅与 Driver 本身相关,而且还与周围环境相互作用。

一般来说,虽然这不限于此,但组件是一种很好的思考方式,可以让您思考如何将您的系统分成更小的部分,这些部分可以分离或附加到系统上,相应地添加或删除其部分功能。