Home > database >  Do class diagrams contain foreign keys and do you show getters/setters/constructors in the method se
Do class diagrams contain foreign keys and do you show getters/setters/constructors in the method se

Time:10-18

I have two questions about class diagrams I will use the below as an example,

Question 1: Do we use foreign keys in the fact table in a class diagram like we do when creating entity relation diagrams so below the field customerid is also a property/field in the order class.

Question 2: In the methods section of the class diagram do we show the constructor and getters/setters methods.

example class diagram

CodePudding user response:

UML lets you decide what you want to show or not:

  • In general, the class diagram shows the associations, without explaining how these associations are implemented. This is different from a crow's foot ERD that can show the link between the table at the key level.
  • However, you can model databases in UML using your own stereotypes to document primary and foreign keys or other elements that are not build-in into UML. It's just that there is no universally accepted notation for that. Here a popular example.

Regarding the operation compartment (aka "method section", in UML a "method" is called "operation"), we represent indeed the relevant operations. The getters and setters can be represented. You can also showw a constructor by preceeding its name with «Create». But you don't have to show all the methods, if it doesn't help to better understand the design.

P.S: You didn't ask, but if you're in DB modelling, you may also think about documenting table triggers in the operation compartment.

  • Related