Master UML Class Diagram Relationships: From Generalization to Dependency
This article explains the six core UML class diagram relationships—generalization, realization, aggregation, composition, association, and dependency—illustrating each with clear diagrams and practical examples, and also recommends popular UML tools for creating these models.
In team collaboration, meetings often rely on diagrams such as flowcharts, sequence diagrams, and especially class diagrams, which clearly describe the concepts being discussed. Mastering class diagrams helps clarify business logic and boosts meeting efficiency.
The following scenario illustrates how to draw a correct class diagram. A company contains many departments, and the company and departments are inseparable. A programmer belongs to a department, but if the department dissolves, the programmer remains a programmer. The programmer constantly uses a phone, and only uses a Mac during work hours. A Mac is a type of computer, and a computer is an implementation of a "computable processor".
Generalization (is‑a)
Generalization represents an “is‑a” relationship; if one object can be expressed as another using “is‑a”, it is a generalization.
In code, this usually corresponds to inheritance from a non‑abstract class.
Realization (implements)
Realization is shown with a hollow‑arrow dashed line. For example, a computer realizes the "computable processor" interface, which in code appears as implementing an abstract class or interface such as Readable or Printable.
Aggregation
Aggregation uses a line with a hollow diamond arrow. In the diagram, a programmer and a department form an aggregation relationship: the part can exist independently of the whole, so if the department disappears, the programmer still exists.
Composition
Composition is depicted with a solid‑diamond line. It also shows a whole‑part relationship, but the part depends strongly on the whole; if the whole (e.g., the company) ceases to exist, the parts (e.g., departments) also disappear.
Association
Association is a simple solid line, optionally with an arrow to indicate direction. It describes a static relationship between classes that does not change with state; for example, a phone is part of a programmer’s environment regardless of work status, typically represented by a class attribute.
Dependency
Dependency is shown with a dashed line ending in an arrow. It describes a runtime relationship where one object uses another, such as a programmer needing a Mac only during work hours, typically expressed in code via constructors or method parameters.
Recommended UML Tools
PlantUML
StarUML 2.0
JUDE‑Community
ProcessOn
STARUML
Visio
Enterprise Architect
LucidChart
Draw.io
Baidu Brain Map
Astah
Review and Mnemonic
Re‑examine the opening diagram to see how each line and arrow conveys meaning. To remember the relationships, use the following poem:
实箭泛化虚实现 虚线依赖实关联 空菱聚合实组合 项目沟通图常见
Now, have you mastered these UML class diagram relationships?
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
