本文介绍了UML关联与组成和详细程度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,提出几个业余UML问题!在创建用于对某些领域概念建模的UML图时,您会遇到一个持有有关另一个概念的某些信息的领域概念,是在该模型本身中保留一个图章/对该实体的引用还是将整个实体保留在模型中更好?请记住,这与创建简单的高级模型有关-我敢肯定,在实施阶段,情况会稍有不同。



例如,以下两个模型中的哪个实际上是正确的?第一个具有组成关系,FlightBooking负责整个Flight。在第二篇中,FlightBooking仅引用了Flight。





第二,在创建高级UML图建模领域概念时,如何您真的打算走很多细节吗?例如,在下图中,航班可以以字符串形式包含有关起点/终点的详细信息,或者我可以为这些概念建模单独的类并创建组成关系。





此外,在上述模型中,航班持有原始地点/目的地时,还有另一件事作为另一个类而不是字符串,两种方法中的哪一种是正确的建模方法?关于何时显示关联和何时显示合成,我感到很困惑。

解决方案

关联

这意味着两个类具有某种关系,可能确实是任何关系。

例如:A使用B,A以给定的方式与B相关。



组成:

这也是用于建模所有权的一种特殊类型的关联。这与聚合非常相似,唯一的区别在于它描述了一个整体部分关系,而部分实体没有自己独立的存在



例如:A由B组成;

很好的解释:


Actually, make that a couple of amateur UML questions! When creating a UML diagram to model some domain concepts and you come across a domain concept that "holds" some information about another concept, is it better to hold a stamp/reference to that entity or hold the whole entity in the model itself? Please bear in mind that this is relating to creating a simple high-level model - I'm sure in the implementation stage things would be slightly different.

For example, which of the two models below is actually correct? The first one has a composition relationship, with FlightBooking holding the whole of Flight. In the second one, FlightBooking just has a reference to Flight.

Secondly, when creating a high level UML diagram modelling domain concepts, how much detail are you really meant to go? For example, in the diagram below, a flight could hold details about origin/destination as strings, or I could model separate classes for these concepts and create a composition relationship. Which of the two is advisable?

Also, just another thing, when modelling the above where a Flight "holds" an orig/destination as another class rather than a string, which of the two ways is the correct way of modelling this? I'm quite confused as to when to show assosciation and when to show composition.

解决方案

Association :
It means two classes have some kind of relationship, could be anything really.
E.g : A uses B, A is related to B in a given way.

Composition :
This is also a special type of association used for modelling 'Ownership'. This is very similar to Aggregation with the only difference that it depicts a Whole-part relationship and the 'part' entity doesn't have its own independent existence

E.g : A consists of B; B is a part of A and hence cannot exist without A.

Good explanation : UML Class Diagram: Association, Aggregation and Composition

这篇关于UML关联与组成和详细程度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:54