0

If I have a clone of a Stackoverflow application, I would have two classes: Question and Tag class, and a relationship between them to be many-to-many.

How would I model this in class diagram? Will I create a class between them?

Note: I'm trying to apply DDD so Question and Tag would be entities

Thank you in advance

bu3abed
  • 21
  • 2
  • If you're trying to apply DDD then don't just design a data model. Focus on behaviors and invariants. Adding, removing tags and what happens should happen to old questions when tags changes over time (renamed, description updated, tag disabled/archived/prohibited, etc.). This is what's going to lead you to the proper design: considering aggregation vs composition and values vs entities. – plalx Jan 23 '21 at 04:04

1 Answers1

1

All depends on what you want to show. Here I propose several ways including bad/incomplete ones explaining their goal/context, rather than to just propose one solution as you can see in the answer of similar question.

Will I create a class between them?

If the question is about UML (class diagram) out of an implementation using Sql or any other database, then the answer is no.

In this context I do not see a reason to have a class-association too, so if you have the classes Question and Tag and a relation there is just

enter image description here

Not sure anyway each tag knows the questions using it, so probably it is just

enter image description here


But if you want to show the implementation using an intermediate table to memorize all the couples then

enter image description here

because the table is unique the attribute table can be defined at the class level (static), but it is also possible to not have these attributes table and probably that table is a singleton

enter image description here

But without additional constraint these two previous ways allow to have for instance a Question not associated with a Tag in the Table. To not have to add constraints better to do

enter image description here

An intermediate way is to use a class-association

enter image description here

but that way partially hides the implementation, and a way to implement the class association is the previous solution. So better to use one of the first 2 ways completely hiding the implementation or the solution with the 4 classes fully showing the implementation.

bruno
  • 32,421
  • 7
  • 25
  • 37