Composite结构图和组件图的区别

Differences between Composite structure and component diagram

美好的一天!

我正在做一些关于复合结构图 (CSD) 的工作,但我无法弄清楚 CSD 和组件图之间的区别。两者在我看来都一样。还是我错了?

我能否像使用组件图一样使用 CSD 对所有情况进行建模?若否,是哪些个案?

什么时候使用 CSD 优于组件图? (反之亦然)

组件图旨在为体系结构建模。我不能用 CSD 模拟相同的架构吗?

谢谢!

其实大多数UML图都是相似的(SD和Timing D除外),你可以随便放什么。在某些图表中使用某些子集更像是一种约定,但没有限制(除了见上文)。

上层建筑 (2.5) 的附件 A 指出:

A UML model consists of elements such as packages, classes, and associations. The corresponding UML diagrams are graphical representations of parts of the UML model.

...

NOTE. This taxonomy provides a logical organization for the various major kinds of diagrams. However, it does not preclude mixing different kinds of diagram types, as one might do when one combines structural and behavioral elements (e.g., showing a state machine nested inside an internal structure). Consequently, the boundaries between the various kinds of diagram types are not strictly enforced.

UML 没有严格定义各种图表类型 ("the boundaries between the various kinds of diagram types are not strictly enforced")。 但是,一般而言,创建仅呈现主题的一种视图的图表是一种很好的做法。

假设您有组件 'Car'、组件 'Wheel' 和组件 'Engine'。引擎驱动前轮,而不是后轮。

组件图 显示组件及其关系。组件是一种特殊的 class。该图不显示组件实例。在示例中,我们将展示三个组件。 Car 与 Wheel 有 1:4 组合关联,与 Engine 有 1:1 组合关联。 Engine 与 Wheel 有 1:2 关联。指定发动机仅连接到前轮并且两个轮必须属于同一辆车并不是微不足道的。您将需要为此编写一些 OCL 约束。

复合结构图展示了另一个组件中包含的组件实例以及这些实例之间的联系(其实我应该用part[=21这个词=] 而不是实例)。此图将引擎和四个车轮显示为汽车组件内的独立块。现在很容易显示引擎如何仅连接到同一辆车的前轮。