组合与依赖关系在类图中的区别? [英] Difference between Composition and Dependency in class diagram?

查看:171
本文介绍了组合与依赖关系在类图中的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有人问了这个问题,但是我还是没有真正得到它,我需要一个具体的答案。谢谢:D

解决方案

由于Gangnus没有正确解释组合的意思,所以我必须这样做。 p>

如Gangnus所解释的, 聚合 是一种特殊形式的关联意义的部分整体关系,但没有精确的语义(UML规范说:共享聚合的精确语义因应用区域和建模者而异)。例如,我们可以在类 Car Engine 之间以及课程讲座由于发动机是汽车的一部分,讲座是课程的一部分。



A 组合 (在UML规范中也称为复合聚合)是一种特殊形式的聚合,一个组件实例是一次最多一个聚合实例的一部分(也就是说,它不能在几个聚合之间共享)。这意味着 Car Engine 之间的聚合是一个组合(因为引擎不能在两个车之间共享同时),而课程讲座之间的聚合不一定是一个组合,因为讲座可以在两个课程(例如数据库管理课程和软件工程课程可以分享关于UML的讲座)。这意味着组合的关联在整体一方结束的多重性是 1 0..1 ,而在非复合聚合的情况下,它也可能 *



除了这个组合的主要特征(要具有独占部分),组合也可能伴随着一个聚合体及其组件之间的生命周期依赖关系,这意味着当一个聚合被删除,它的所有部分都被删除。然而,这只适用于一些组合的情况,而不适用于其他的,因此不是一个定义的特征。 UML规范说明:在复合实例被删除之前,可能会从组合实例中删除一个部分,因此不会作为组合实例的一部分进行删除。在我们的汽车 - 发动机组合的例子中,很明显,发动机可以从汽车上移除汽车被毁坏,在这种情况下,发动机不会被破坏,可以重新使用。


I know, somebody had asked the same question about this case, but i still don't really get it, i need a specific answer. Thank you :D

解决方案

Since Gangnus did not correctly explain the meaning of composition, I'll have to do it.

As explained by Gangnus, an aggregation is a special form of association with the intended meaning of a part-whole-relationship, but without a precise semantics (the UML spec says: "Precise semantics of shared aggregation varies by application area and modeler"). For instance, we can model an aggregation between the classes Carand Engine and between the classes Courseand Lecture since an engine is part of a car and a lecture is part of a course.

A composition (also called "composite aggregation" in the UML spec) is a special form of aggregation, where a component instance is part of at most one aggregate instance at a time (that is, it cannot be shared between several aggregates). This means that the aggregation between Carand Engine is a composition (because an engine cannot be shared between two cars at the same time), while an aggregation between Courseand Lecture is not necessarily a composition since a lecture can be shared among two courses (e.g. a database management course and a software engineering course could share a lecture on UML). This implies that the multiplicity of a composition's association end at the aggregate side is either 1or 0..1, while it may be also * in the case of a non-composite aggregation.

In addition to this main characteristics of a composition (to have exclusive parts), a composition may also come with a life-cycle dependency between an aggregate and its components implying that when an aggregate is deleted, all of its parts are deleted with it. However, this only applies to some cases of composition, and not to others, and it is therefore not a defining characteristic. The UML spec states: "A part may be removed from a composite instance before the composite instance is deleted, and thus not be deleted as part of the composite instance." In our example of the Car-Engine composition, it's clearly the case that the engine can be removed from the car before the car is destroyed, in which case the engine is not destroyed and can be re-used.

这篇关于组合与依赖关系在类图中的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆