简体   繁体   English

类图组成关系

[英]class diagram Composition Relationship

Should the owner have an attribute of the owned object type in a class diagram composition relationship? 所有者是否应该在类图组成关系中具有所拥有对象类型的属性? Or is having a key or related property considered a composition, too? 还是拥有键或相关属性也被认为是构成?

My example is: 我的例子是:

I have two classes "user" and "image". 我有两个类“用户”和“图像”。 The user logically has an image. 用户在逻辑上具有图像。 In the code the user class contains an attribute for the image name (the key) but not an object of type "image". 在代码中,用户类包含图像名称(键)的属性,但不包含“图像”类型的对象。

The relationships in UML should be mostly independent of the actual implementation. UML中的关系应基本上独立于实际实现。 What the composition relationship expresses is a lifetime dependency. 组成关系表示的是生命周期依赖性。

Objects that are composed are responsible for creation, usage and destruction of the owned objects. 组成的对象负责创建,使用和销毁所拥有的对象。 Whether it is realized through a reference to the actual object or a placeholder (in your case the name of the image), is not that much of a difference. 无论是通过引用实际对象还是通过占位符(在您的情况下为图像的名称)来实现,都没有太大的区别。

In a composition the owned class ("image") should not be able to exist without its owner class ("user"). 在合成中,如果没有所有者类(“用户”),则所有者类(“图像”)应该不存在。 In your case I'd say it is possible, so you should change the relationship in your model accordingly. 就您的情况而言,我认为这是可能的,因此您应该相应地更改模型中的关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与抽象类的构图关系 - composition relationship with abstract class 这是实体关系图还是类图 - Is this an Entity Relationship Diagram or a Class Diagram 显示双向和组合关系UML类图 - Display bidirectional and composition relation UML class diagram 类图中的聚合和组合关系 - Aggregation and Compostion relationship in class diagram 类和枚举之间的构成关系正确吗? - Is the composition relationship correct between a class and an enumeration? 使用“具有”关系或构图将向量从一个类转移到另一个类 - putting a vector from one class to another using the “has a” relationship or composition UML Class 图:Object 通过构造函数关系? - UML Class Diagram: Object passed through constructor relationship? 有关项目管理中关系类型的UML类图 - UML class diagram about relationship types in project management 抽象类是否可以作为其他具体类的成员构成关系? C ++ - Can an abstract class be member of other concrete class as composition relationship ? c++ 如何使用序列图显示 class 和另一个 class 之间的关系,该 class 将类实例的实例作为输入? - How to show the relationship between a class and another class that takes the instance of the class's instance as an input with a sequence diagram?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM