[英]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.