UML类图:关联还是组成? [英] UML class diagram: Association or Composition?

查看:101
本文介绍了UML类图:关联还是组成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下情况的关系有些困惑.当使用构图示例时,它们总是倾向于使用简单的示例,例如房间和建筑物.

I'm a little confused on what the relationship would be for the scenario below. When examples of composition are used they always tend to use simple ones such as rooms and a building.

这种情况是记录了医生的就诊记录.是关联,组成还是两者的结合?我在下面提供了一张我被困在其中的两种不同关系的图片.我在考虑组成是因为这次访问属于每一方?

This scenario is that doctor patient visits are recorded. Would it be an association, composition or a mix of both? I've included a picture below of the two different relationships I am stuck between. I am thinking composition because the visit belongs to each party?

派生关联

推荐答案

一般来说,我的经验法则是,如有疑问,请始终使用关联而不是合成/聚合.我这样做的原因是:

In general my rule of thumb is that when in doubt, always use association rather than composition/aggregation. My reasons for this are:

(1)在面向对象的分析和设计信息系统 Wazlawick指出,组合和聚集的真正优势 在于零件的属性通常用于推导整体的属性.作为示例,他提到订单(整个)的总价值是由其每个项目(零件)的价值得出的.但是,这对他来说是设计问题,而不是概念模型 关心.从概念建模的角度来看,他认为建模者经常不恰当地应用聚合和组合(即,在没有整体关系的情况下),并且他们的使用很少有真正的好处.因此,他建议避免甚至取消其使用.

(1) In Object-oriented analysis and design for information systems Wazlawick notes that the real advantage of composition and aggregation is that the attributes of the parts are often used to derive attributes of the whole. As an example he mentions that the total value of an order (whole) is derived of the value of each of its items (parts). However, this to him is a design concern rather than a conceptual modelling concern. From a conceptual modelling perspective, he believes that modellers often apply aggregation and composition inappropriately (that is, where whole-part relations are not present) and that their use seldom have real benefit. Hence he suggests avoiding or even abolishing their use.

(2)UML旨在通过组合/聚集提供部分整体关系的半形式化.但是,正式建立整体关系是一项艰巨的任务,UML规范并没有做到这一点.确实,许多研究人员指出了有关聚合和组成的各个方面,其中未指定UML规范.所有人都提出了解决UML规范缺点的方法,但是迄今为止,这些更改尚未并入UML规范中.例如,请参见介绍整体关系.

(2) UML aims to provide a semi-formalization of part-whole relations through composition/aggregation. However, formalization of part-whole relations is a non-trivial task, which the UML specification does not do justice. Indeed, a number of researchers have pointed out various aspects with regards to aggregation and composition in which the UML specification is under specified. All have proposed means for addressing the shortcomings of the UML specification, but to date these changes have not been incorporated into the UML specification. See for instance Introduction to part-whole relations.

这篇关于UML类图:关联还是组成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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