admin管理员组

文章数量:1122846

the difference between these is that: the first image, the simple many-to-many association indicates that there can only be one association between an instance of user and product. The second instead indicates that there can be multiple associations between the same user and product. That is, if we have user1 and product1 they can also create two associations. The third instead I can't explain its usefulness, can you tell me?

the difference between these is that: the first image, the simple many-to-many association indicates that there can only be one association between an instance of user and product. The second instead indicates that there can be multiple associations between the same user and product. That is, if we have user1 and product1 they can also create two associations. The third instead I can't explain its usefulness, can you tell me?

Share Improve this question asked Nov 21, 2024 at 16:34 dokdok 3917 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 1

You are right. There is no meaningful difference between 2 and 3.

There used to be, but it was thrown out by the UML taskforce in issue UML22-21, albeit for very good reasons. Since this effectivly makes association classes obsolete, issue UMLR-443 tried to get it back in, but this is still open. So, it is really up to your preferences.

Please note, that in the first case, the associations ends could be {non unique} (default is {unique}). Then there could be many links between any pair of instances. And then all three diagrams mean the same.

PS: You write "there can only be one association between an instance of user and product". "association" should be replaced with "link". Remember that links are instances of associations.

A class diagram can serve several purposes:

  • In a domain model: to model the real world;
  • In a conceptual model: to model the objects in an application, from a user's perspective;
  • In a physical data model: to model the tables and their relationships in a relational database;
  • In a physical class model: to model the classes present in the source code;
  • etc.

The association class is mostly used in domain models and conceptual models. It shows that, in this case, User and Product are related and that Purchase provides more details about this relationship.

The third option also appears in such models, if the modeler views the User-Purchase relationship as a different relationship than the Purchase-Product relationship.

In other words, your choice depends on how you perceive the relationship(s) and what you want to convey to the reader.

In physical models, the third option is usually preferred over the second option, because the database or programming language doesn't have the concept of an association class and the model must visualize the implementation.

本文标签: