Home > Mobile >  Class Diagram OOP
Class Diagram OOP

Time:05-03

If two classes are associated regularly, do they need to contain each other's objects as attributes? For example, a Post class and a Comment class on a social media platform. Should the Post class contain an array of comment objects as an attribute? And should the Comment class contain a post object as an attribute?

CodePudding user response:

This is a common mistake of redundant information. It does not need to be shown in the class diagram as a field because it is derived from the association.
This is a class diagram that covers what you have mentioned in its simplest form. enter image description here

As you can see, objects for each class do not need to be added as fields.

  • Related