简体   繁体   English

UML概括和关系

[英]UML Generalization and Relationships

Currently we have a structure like the following in our UML Class Diagram: 当前,我们的UML类图中具有如下结构:

Node --1------------*-- Data
 ^                        ^
 |                        |
SpecialNode--1----*--SpecialData

Eg SpecialNode is a specialization of the class Node and SpecialData is a specialization of the class Data. 例如,SpecialNode是Node类的专业,而SpecialData是Data类的专业。

The idea is that each SpecialNode only has SpecialData, and no 'normal' Data. 这个想法是每个SpecialNode仅具有SpecialData,而没有“普通”数据。 However, some would argue that since a SpecialNode is a Node, it can have relationships to both Data and SpecialData. 但是,有人会争辩说,由于SpecialNode是一个Node,因此它可以与Data和SpecialData都有关系。

Is there any reference material available that would clarify if SpecialNode can have only SpecialData? 是否有任何参考资料可以阐明SpecialNode是否只能拥有SpecialData? If not, how could we inforce this (in a clean way). 如果没有,我们怎么能(以一种干净的方式)加强这一点。

Kind Regards, Joos 亲切的问候,Joos

Indeed, such modeling implies that SpecialNode inherits all the properties of Node , including Data . 实际上,这种建模意味着SpecialNode继承了Node所有属性,包括Data Otherwise it would contradict the Liskov Substitution Principle which is an important rule for good design. 否则,它将与《 里斯科夫替代原理》相抵触,后者是良好设计的重要规则。 I would suggest not to define your Node and SpecialNode as "having" Data or SpecialData but rather have an interface to Data . 我建议不要将NodeSpecialNode定义为“具有” DataSpecialData ,而应具有 Data 的接口 For Node it will be associated with Data object and for SpecialNode it will be associated with SpecialData object. 对于Node ,它将与Data对象关联,对于SpecialNode ,将与SpecialData对象关联。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM