Crispus Elischama
Crispus Elischama

Reputation: 59

How to model a hierarchy of (sub)categories in a Class Diagram and in an SQL Table Model?

Someone could help me please?

I want to make a class diagram in UML, and I have CATEGORY class which can have SUBCATEGORIES and so on. How can I manage it in class diagram, thus in mysql database?

Thanks in advance

Upvotes: 0

Views: 1106

Answers (1)

Gerd Wagner
Gerd Wagner

Reputation: 5673

A hierarchy (or tree) of categories is modeled with a recursive one-to-many association, which associates the Category class with itself, as shown in the following diagram:

enter image description here

Such an Information Design Model can be transformed into an OOP Class Model and into an SQL Table Model, like so:

enter image description here

Notice how the superCategory column is designated as a foreign key referencing the categories table in the table model: by a UML dependency arrow stereotyped as «fk».

I hope you can figure out yourself how to code the SQL Table Model in an SQL Create Table statement.

p.s.: For more about how to model databases with UML CLass Diagrams seee https://stackoverflow.com/a/21394401/2795909

Upvotes: 2

Related Questions