Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I put id attributes in UML class diagrams?

I'm drawing up some class diagrams here. I am wondering should I include auto-incremented attributes like the primary key user_id in the User table? Should I include these primary/foreign key id attributes in my classes? It certainly seems like I should, eg., orderId is a critical identifier for orders in the Order table, even though it is 'only' an arbitrary auto-incremented integer...

like image 300
csss Avatar asked Oct 04 '22 22:10

csss


1 Answers

Class diagrams can be utilized for different purposes, at different levels. Three common usages are design, analysis and data modeling.

1- Analysis class diagrams show the entities and their relationships and model your problem domain (no solution or technology involved)

2- Design class diagrams model your solution and may contain fabric classes. They are very close to your code.

3- Data modeling class diagrams are like entity relationship diagrams (ERD). They are used to model the database tables; they contain primary keys, foreign keys and so on.

So if you are using a class diagram for modeling your database, the answer is yes, otherwise no.

The only reason you would have a primary key field in a class is when your class is a kind of Object Relational Mapper. In that case yes, include the id attribute.

If you are using Enterprise Architect, it has a special class diagram template for data modeling with all the required stereotypes like primary and foreign keys.

like image 135
jurgenreza Avatar answered Oct 10 '22 02:10

jurgenreza