Search code examples
recursionclass-diagram

class diagram, how to show recursive class?


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.


Solution

  • 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.