我应该选择哪种关系:关联还是聚合?

发布于 2024-10-15 13:50:19 字数 293 浏览 5 评论 0原文

我的数据库中有一个教授表。我想为代码隐藏部分创建一个 UML 图。

类结构将是: - 一个 Profesor 类,映射数据库表中的信息(id、名字等) - ProffesorDAL 类连接到数据库并查询它以添加、删除、更新 Proffesor 实例 - 3种添加/删除/更新教授的表单,通过访问ProffesorDAL类

我认为表单-ProffesorDAL关系是一种组合关系。这是正确的吗? ProfesorDAL-Proffesor 关系怎么样,它是聚合还是只是关联?表单与教授关系的最佳 UML 关系是什么?

谢谢!

I have a Proffesor table in a database. I would like to create an UML diagram for the code-behind part.

The class structure would be:
- a Proffesor class that maps the information from the database table (id, first name, etc)
- a ProffesorDAL class which connects to the DB and queries it in order to add,remove,update Proffesor instances
- 3 forms which add/delete/update proffesors, by accesing the ProffesorDAL class

I thought that the forms-ProffesorDAL relationship is a composition relationship. Is this correct?
How about the ProffesorDAL-Proffesor relationship, could it be aggregation or is it just association? What's the best UML relationship for the forms-Proffesor relationship?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝不服输 2024-10-22 13:50:19

我首先假设存在关联,然后分析和设计两者之间是否应该有更强的关系。

我的问题是“它拥有它吗”。例如,我想说一辆汽车有 4 个轮子(还有一长串其他项目)。

在我的标准设计中,我的 UI 和 DAL 之间有一个 BLL。我首先假设我的三个之间存在松散的关联,后来我得出的结论是,BLL 和 DAL 在某种程度上有密切的联系,并且可以从紧密的联系中受益。

至于教授课程,我认为这是一个模型课程。模型类我只有松散​​的连接/知识 - 这意味着它们仅作为参数(关联)出现。我的 DAL 与我的模型类(聚合)没有很强的联系。它们只是消息带来者、复杂的整数和布尔值。

I'd start by assuming association and from there to analyse and design if there should be a stronger relation between the two.

My question goes "Does it own it". Example I'd say a Car owns 4 wheels (among a long list of other items).

In my standard design I have a BLL between my UI and DAL. I start by assuming a loose association between my three, later I reach the conclusion that the BLL and DAL are somewhat closely connected and could benefit from a strong tie.

As for the Professor class, I assume this to be a Model class. Model classes I only have a loose connection / knowledge to - meaning they appears only as parameters (association). My DALs do not have a strong connection with my Model classes (aggregation). They are but Message bringers, complex ints and bools.

北斗星光 2024-10-22 13:50:19

UML 聚合关系几乎毫无价值——它造成的混乱远多于价值。它只有一个有用的属性,即如果用于递归关系,则生成的对象结构是非循环的。

实在不值得为此纠结。我的建议是使用简单的二元关联并集中精力获得正确的基数。这更加有用和有价值。

嗯。

The UML Aggregation relationship is almost worthless - it creates far more confusion than value. It has only one useful property, namely that if used in a recursive relationship, the resulting object structure is acyclic.

It's really not worth getting hung up about. My advice would be to use a simple binary association and concentrate on getting the cardinality right. That's a lot more useful and valuable.

hth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文