开发者

Which relationship should I choose: association or aggregation?

开发者 https://www.devze.com 2023-02-09 01:51 出处:网络
I have a Proffesor table in a database. I would like to create an UML diagram开发者_JS百科 for the code-behind part.

I have a Proffesor table in a database. I would like to create an UML diagram开发者_JS百科 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!


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消