1

I just wanted to ask if my comment class has a list of comments then how is this shown in a class diagram?

I am developing a blog in MVC and I'm getting confused between aggregation and composition. A post is made by only a staff, a comment is made on either a comment or post and made by only a customer. Is this aggregation or composition. Please help.

1 Answers1

1

if my comment class has a list of comments then how is this shown in a class diagram?

With a link to itself like this (shows composition but see comment below):

enter image description here

It's technically probably composition because a comment belong to exactly one other comment or no comment in the case of a top level comment, but you can use aggregation, composition, or just an association with multiplicity explicitly listed (aggregation and composition are just types of associations). Using an association is probably best to avoid confusion and arguments about the difference between composition and aggregation.

spinkus
  • 7,694
  • 4
  • 38
  • 62
  • thanks for the response that's what i'll do – hashim mahmood May 04 '21 at 02:56
  • One last question if u have the time: if my class is declared like this " public class Database_Initialiser : DropCreateDatabaseAlways" What is the relationship on a class diagram between the context and initilaiser atm I have put association, is that correct? – hashim mahmood May 04 '21 at 02:59
  • In this case the "Initialiser" inherits `DropCreateDatabaseAlways`. See https://stackoverflow.com/questions/4786771/uml-class-diagram-and-generics for how to represent generic relationships. It also depends on how formal you want to be, it's almost never wrong to do a dependency (dotted arrow) between to classes, it's just vague. Sometimes I start with dependencies then get more concrete later. – spinkus May 04 '21 at 03:17