Search code examples
oopumldata-modelingcardinality

Class diagram of category and sub-category


I have a simple relationship between product and category I came up with this diagram:

enter image description here

  • A product can be assigned to 1 or many categories
  • A category can have 0 or many sub-category
  • A category can have 0 or 1 parent category
  • When you delete a category the sub-categories still exist.

I want to be sure that the diagram has a correct cardinality, especially category to category relation.


Solution

  • Almost correct.

    enter image description here

    Use roles to clearly identify parent/sub-category along with their multiplicities. The hollow diamond makes it a shared aggregation which means the sub-category lives independent of its parent (else you would use a filled diamond).