UML类图中的关系 [英] Relationships in a UML class diagram

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

问题描述

我有一个使用树,节点和边缘类(我需要边缘类!)对树进行建模的应用程序,我不确定如何在类图中表示关系。我已经读过其他文章,但是仍然有疑问。

I have an application that models a tree, with classes Tree, Node and Edge (I need the Edge class!), and I'm not sure how to represent the relationships in the class diagram for this. I've read other posts about this, but am still in doubt.

Tree对象有一个指向Node(其根)的指针,我相信它可以定义一个双向关联(树-> 节点)的双向。

The Tree object have a pointer to a Node (its root), which I believe defines an one-way association (Tree -> Node) with multiplicity 1..1 in both ends. Is it right?

每个Node对象都有指向其边缘的指针(Edge对象)。由于这些边缘仅在节点存在的情况下存在,因此我相信这是一个组合关联。

Each Node object have pointers to the edges that comes out of it (Edge objects). Since these edges only exist if the node exist, I believe it's a composition association.

但是然后,在每个Edge对象中,都有一个指向目标对象Node的指针。边缘。考虑到我已经具有上述的节点-> 边缘组成,我该如何表示这种关系?

But then I have, in each Edge object, a pointer to the target Node of the edge. How can I represent this relationship, considering I already have the Node -> Edge composition described above?

也,如果您仍在阅读:),则每个Node都有一个指向其父Node的指针。在这里,我将使用单向一元关联,但是我不知道用于此关系的名称。

Also, if you're still reading :), each Node have a pointer to its parent Node. Here, I would use an one-way unary association, but I don't know which name to use for this relationship.

感谢您的帮助。

推荐答案

-Tree对象具有一个指向Node(其根)的指针,我认为它定义了单向
-两端的多重性为1..1的-association(树->节点)。是不是?

--The Tree object have a pointer to a Node (its root), which I believe defines an one-way --association (Tree -> Node) with multiplicity 1..1 in both ends. Is it right?

否,多重性应为0..1-1-(并非所有节点都将是树的根)

No, the multiplicity should be 0..1 - 1 (not all nodes will be the root of a tree)

您还应该考虑Edge是否真的是一个类。如果您不需要存储有关边缘的任何类型的信息(即未标记标签),则可以将边缘建模为节点之间的二进制关联

You should also think whether Edge is really a class or not. If you don't need to store any kind of information about the edges (i.e. they are not labelled), I'd just model edges as a binary associations between nodes

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

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