我应该选择哪种关系:关联还是聚合?
我的数据库中有一个教授表。我想为代码隐藏部分创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我首先假设存在关联,然后分析和设计两者之间是否应该有更强的关系。
我的问题是“它拥有它吗”。例如,我想说一辆汽车有 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.
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.