Class Diagrams are the most common and easy way to depict the basics of a system’s design. The arrows that represent relationship between classes and interfaces are the most important but the most challenging part of Class Diagrams. People often face the problem of choosing the right type of the arrow to reflect the nature of relations between entities.
This guide aims to help you with choosing the right arrow types and quickly come up with an elaborate class diagram.
But, first of all, a few words about Association, Composition and Aggregation.
Composition and Aggregation are subtypes of Association that can be used interchangeably depending on specifics of relationship between entities you want to depict on a diagram.
An Association reflects relation between two classes. Use Association arrow when two classes need to communicate and either (or both) class(es) hold reference to the second one. Association relationship is “stronger” than Dependency relationship, it implies a closer connection between entities.
Aggregation / Association
Aggregation implies that two classes are associated, it brings in more details regarding the nature of the relationship: the child can exist independently of the parent.
Composition / Association
Composition implies that two classes are associated and it adds the following details: within a Composition sub-objects are strongly dependent on a whole. Objects of the types are instantiated together and have common lifecycle.
Dependency relationship implies that two elements are dependent on each other. It is used to reflect that one class interacts with another one, receives an instance this class as a method parameter. Compared to Association, Dependency relationship is weaker.
Use Inheritance when you want to show that one class inherits from another one.
Enjoyed the article? Follow me on Instagram for more insights on game architecture and software design.