UML 类聚合到自身 [英] UML class aggregating to self

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

问题描述

我和我的小组正在制作一个程序,其中我们有一个树形结构.在这个树结构中,我们已经使它成为一个类别可以包含它自己.该计划基于您的开支,例如:

My group and I are making a program, where we have a tree structure. In this tree structure we have made it such that a category can contain it self. The program is based on your expenses, so an example could be:

您购买了 4 杯牛奶.这 4 种牛奶被放置在牛奶"类别中.牛奶的每个条目都在另一个类别中汇总了价格(以及其他个人信息).

You have bought 4 milk. The 4 items of milk are placed in the category "Milk". Each entry of milk has the price (along with other individual information) in another class which category aggregates.

诀窍是我们希望类别类能够自己包含它,所以:

The trick is that we want the category class to be able to contain it self, so:

牛奶"类别是乳制品"类别的一部分,在术语杂货"类别中.

The category "milk" is part of the category "Dairy Products", which in terms are part of the category "Groceries".

我们希望这样做的原因是,我们可以在当时批量移动产品.因此,如果您想将 Milk 移至名为Morning Stuff"的类别,则不必移动每一个类别,而只需移动整个类别.

The reason we want it to be like that, is so we can move batches of products at the time. So if you want to move Milk to a category called "Morning Stuff" you wouldn't have to move every single one, but instead just the entire category.

图片是我们当前类别类的建模方式,但我们被告知我们无法在没有更多解释的情况下进行建模.UML 允许这样做吗?如果没有,我们如何使用 UML 对其进行建模?

The picture is how our current category class is modelled, but we were told we couldn't do it without much further explanation. Does UML allow this? If not, how can we model it with UML?

推荐答案

是的,UML 允许从类到自身的关联.同样,聚合甚至组合也可以通过这种方式进行.

Yes, UML allows associations from a class to itself. Likewise aggregations and even compositions are allowed this way.

您发布的图片显示了一个聚合,而根据您的描述,我会选择一个组合(实心菱形):一个类别有一个或没有父级;类别在某种程度上由其子项定义;如果一个类别被删除,所有子项也会被删除.

The image you posted shows an aggregation while from your description I would have chosen a composition (filled diamond): a category has one or no parent; a category is somewhat defined by its children; if a category gets deleted all children are deleted as well.

可以找到聚合和组合之间更长的比较此处.

A longer comparison between aggregation and composition can be found here.

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

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