UML Class Diagram Relationships Explained with Examples

Class diagrams are the main building blocks of object-oriented modeling so it is important that you understand the various class diagram relationships and how they affect your solution. We have listed them below with examples.

Creately simplifies creating class diagrams by showing the logical relationship based on context.

Class Diagram Relationships

Classes are interrelated to each other in specific ways. In particular, relationships in class diagrams include different types of logical connections. The following are such types of logical connections that are possible in UML:

Class Diagram Relationships ( UML )
Relationships in UML class diagrams


Association - One of the most common in class diagram relationships

is a broad term that encompasses just about any logical connection or relationship between classes. For example, passengers and airline may be linked as above.

Directed Association

Directed Association Relationship in UML Class diagrams
Directed Association

refers to a directional relationship represented by a line with an arrowhead. The arrowhead depicts a container-contained directional flow.

Reflexive Association

Reflexive Association Relationship in UML Class diagrams
Reflexive Association

This occurs when a class may have multiple functions or responsibilities. For example, a staff member working in an airport may be a pilot, aviation engineer, ticket dispatcher, guard, or maintenance crew member. If the maintenance crew member is managed by the aviation engineer there could be a managed by relationship in two instances of the same class.


Multiplicity Relationship in UML Class diagrams

is the active logical association when the cardinality of a class in relation to another is being depicted. For example, one fleet may include multiple airplanes, while one commercial airplane may contain zero to many passengers. The notation 0..* in the diagram means “zero to many”.


Aggregation Relationship

refers to the formation of a particular class as a result of one class being aggregated or built as a collection. For example, the class “library” is made up of one or more books, among other materials. In aggregation, the contained classes are not strongly dependent on the lifecycle of the container. In the same example, books will remain so even when the library is dissolved. To show aggregation in a diagram, draw a line from the parent class to the child class with a diamond shape near the parent class.

To show aggregation in a diagram, draw a line from the parent class to the child class with a diamond shape near the parent class.


Composition Relationship in Class Diagrams

The composition relationship is very similar to the aggregation relationship. with the only difference being its key purpose of emphasizing the dependence of the contained class to the life cycle of the container class. That is, the contained class will be obliterated when the container class is destroyed. For example, a shoulder bag’s side pocket will also cease to exist once the shoulder bag is destroyed.

To show a composition relationship in a UML diagram, use a directional line connecting the two classes, with a filled diamond shape adjacent to the container class and the directional arrow to the contained class.

Inheritance / Generalization

Inheritance Relationship in UML Class diagrams

refers to a type of relationship wherein one associated class is a child of another by virtue of assuming the same functionalities of the parent class. In other words, the child class is a specific type of the parent class. To show inheritance in a UML diagram, a solid line from the child class to the parent class is drawn using an unfilled arrowhead.


Realization Relationship in UML Class diagrams

denotes the implementation of the functionality defined in one class by another class. To show the relationship in UML, a broken line with an unfilled solid arrowhead is drawn from the class that defines the functionality of the class that implements the function. In the example, the printing preferences that are set using the printer setup interface are being implemented by the printer.

Drawing class diagrams using Creately

We’ve given a lot of thought to relationships when we built our class diagramming tools. Our connectors adjust to the context and show only the most logical relationships when connecting classes. This significantly reduced your chances of making a mistake.

Create a class diagram >>

Drawing from scratch can be cumbersome. You can get started immediately using our professionally designed class diagrams. Browse our class diagram examples and pick the one that’s closely related to your system.

What are the Class Diagrams?

Class diagrams are the main building block in object-oriented modeling. They are used to show the different objects in a system, their attributes, their operations, and the relationships among them.

The following figure is an example of a simple class:

Simple Class diagram
Simple class diagram with attributes and operations

In the example, a class called “loan account” is depicted. Classes in class diagrams are represented by boxes that are partitioned into three:

  1. The top partition contains the name of the class.
  2. The middle part contains the class’s attributes.
  3. The bottom partition shows the possible operations that are associated with the class.

The example shows how a class can encapsulate all the relevant data of a particular object in a very systematic and clear way. A class diagram is a collection of classes similar to the one above.

Any More Questions About Class Diagram Relationships?

I hope I’ve clearly explained the various relationships between class diagrams. They are not as complex as you think and can be mastered with some practice. And by using our tool you shouldn’t have any trouble coming up with class diagrams. If you have any more questions don’t hesitate to ask in the comments section. Also, check out this guide to UML Diagram Types with Examples for further reading.


1. UML basics: The class diagram An introduction to structure diagrams in UML 2 by Donald Bell

2. Class diagram as published on the Wikipedia website

3. The UML Class Diagram Part 1 as published on the website

4. The Class Diagram from Visual Case Tool – UML Tutorial as published on Visual Case website

5.  Associations as published on the Sybase website

Join over thousands of organizations that use Creately to brainstorm, plan, analyze, and execute their projects successfully.

Get started here



Software engineer turned tech evangelist. I handle marketing stuff here at Creately including writing blog posts and handling social media accounts. In my spare time, I love to read and travel.


  1. Kirabo Ibrahim

    Thank you so much for this helpful information, it really cleared my confusion I had about uml class diagrams

  2. Virendra samundra singh

    How can I find the class in a project? I mean to say how I can find how many class in a project?
    Is there any technique?

  3. kaushik

    It should be like this – ” a broken line with an unfilled solid arrowhead is drawn from the class that defines the functionality “to” the class that implements the function.”

  4. Brajesh Soni

    For Inheritance / Generalization : bank account, logically seems to be parent class to fixed account. So unfilled arrowhead has to be end at bank account box.

  5. Saqib

    Good Explanation.

  6. Aditya

    Isnt the realization line direction other way round?
    a broken line with an unfilled solid arrowhead is drawn to the class that defines the functionality from the class that implements the function

    • Goteguru

      The diagram might be correct. The explanation should be something like this: the printer setup implements the generic printer functionality.

      • Xavi

        The problem is what has written down the author. He says “In the example, the printing preferences that are set using the printer setup interface are being implemented by the printer.” so it’s the opposite of what you are saying.

  7. mahadev

    What does 1..4 mean in association

  8. cate

    Amazing content here, it is very much helpful. Thank you for sharing.

  9. Regha

    It was of great help Nishadha!tnku so mch! 🙂

  10. indhumathi

    explanation is good and when u give with example it will be easy for beginners………

  11. shereeff

    Thanks you so much

  12. Manana Dero

    thks so much.i got to understand class diagrams the lay man’s way.big up

  13. Mohsen

    very good but, you can summarize your words in few words

  14. yousuf

    in composition diagram above, do you think the books wouldn’t survive the library-death??. A more fitting example would be human and leg OR bulb and filament OR current and voltage, etc.

  15. aya

    can you tell me more examples with explanations

  16. Jimmie

    Interesting the concept of aggregation and composition. Got few insights more to enrich my point of view frame.

    Thanks fir sharing Nishadha, have a nice day.


  17. Blazy prince

    on Directed association ,how does planer be the contained of passenger(container) I think it is wrong if not explain to me please!!!

  18. Darren Bruce

    Good summary, just one thing, you have the wrong example in Composition. You should Library and Books again (as per Aggregation) and then talk about Shoulder Bag and Shoulder Bag Pocket in the text. Basically you need to relabel the diagram example. Cheers

  19. accounting software

    Large number of individuals looks for these details but they will not get effective one. I truly several thanks for discussing it

  20. Thashreef

    What is the Relationship between Employee and Employee_Dependent Class

  21. mcr1234

    very useful, thank you very much ^^

  22. priyansh

    how do i show primary key in class diagram????

  23. Prashanth

    The example you’ve given for inheritance/generalization should be the other way round. Bank Account should be the Parent. Fixed, Savings accounts should be the children. Bank account will hold the general attributes/ methods where as the Fixed account will have specific attributes/ methods inheriting the rest from the Bank account.

  24. Saad Malik

    Out of curiosity, in the Airplane to Passengers Multiplicity example, shouldn’t this relationship be a Aggregation? In general, could you please give an example of when an association is more apt than an aggregation/composition with multiple objects?

  25. Uzma Pathan

    Hi, I have a query. Can realization relationship exist between a Package and an Interface? Can we draw a realization relation (Empty head arrow) between a Package and an Interface in UML?

  26. Akash Agrawal

    nice points which u have clear to me….can u have explain class diagram of online examination….

  27. Nishadha

    Hi Satish,
    Maybe you can refer our ER diagram tutorial to help with your project.

  28. satish

    hey hii can you help us out in making er diagram for our project…

  29. Thanks a lot.. I was little confused about simple and directed associations but your post cleared my doubt.

  30. Nishadha

    Hi Agecoat,
    Thanks for visiting and leaving a comment. I think the example is valid but a better job could be done by adding an example. I have added an example to make it more clear.

    • aliy

      thank for your effort i need some help in terms of this diagram am a student at kampala uganda i have a scenario but i want come along with class diagram , state chart, use case diagram and collaboration with sequence diagram i need your assistance,

      Mental Health Care Patient Management System
      This case study is based on a real system that is in use in a number of hospitals.
      For reasons of commercial confidentiality, I have changed the name of the
      system and have not included information about any specific system features.
      1. Background
      A regional health authority wishes to procure an information system to help
      manage the care of patients suffering from mental health problems. The overall
      goals of the system are twofold:
      1. To generate management information that allows health service managers to
      assess performance against local and government targets.
      2. To provide medical staff with timely information to facilitate the treatment
      of patients.
      The health authority has a number of clinics that patients may attend in
      different hospitals and in local health centres. Patients need not always attend
      the same clinic and some clinics may support ‘drop in’ as well as pre-arranged
      The nature of mental health problems is such that patients are often
      disorganised so may miss appointments, deliberately or accidentally lose
      prescriptions and medication, forget instructions and make unreasonable
      demands on medical staff. In a minority of cases, they may be a danger to
      themselves or to other people. They may regularly change address and may be
      homeless on a long-term or short-term basis. Where patients are dangerous,
      they may need to be ‘sectioned’ – confined to a secure hospital for treatment
      and observation.
      Users of the system include clinical staff (doctors, nurses, health visitors),
      receptionists who make appointments and medical records staff. Reports are
      generated for hospital management by medical records staff. Management have
      no direct access to the system.
      The system is affected by two pieces of legislation (in the UK, Acts of
      Parliament). These are the Data Protection Act that governs the confidentiality
      MHCPMS Case Study 2
      of personal information and the Mental Health Act that governs the compulsory
      detention of patients deemed to be a danger to themselves or others.
      The system is NOT a complete medical records system where all information
      about a patients’ medical treatment is maintained. It is solely intended to
      support mental health care so if a patient is suffering from some other unrelated
      condition (such as high blood pressure) this would not be formally recorded in
      the system.

      • adeyeni

        mail me lets discuss, im also doin an hospital management system

  31. Agecoat

    Your explanation of the reflexive association strikes me as odd.

    Your explation of reflexive depicts an association class between ‘airport’ and ‘staff’ in which the association depicts the ‘multiple roles’ of the particular ‘staff’ in regard to the ‘airport’.

    The reflexive association, to me, depicts the situation of a relation between equally typed instances, for example, like in a mesh network or in a (genealogical) parent – child construction of type Person.

    Also consider adding the association class as a conceptual class relationship construct.

  32. amal

    nice effort to help people… i appreciate 🙂

  33. sid

    Hi Nishadha, your explanation was very informative,can you send me the class modellind diagram for bill splitting applications

  34. Nishadha

    Hi Rajasekhar,
    You can browse through our UML class diagrams examples and find a good one that matches your needs.

  35. Rajasekhar Reddy

    Hi Nishada,your explanation is very clear to understand,can you send me the class modelling example of hospitality management system.

  36. Wimal Perera

    Hi Nishi, its a great blog man. I just accidently came across this when browsing web.

    Great work!! Keep it up.

  37. iraj osolli

    thank u
    very nice…………..

  38. Nishadha

    Hi noway,
    You’re correct. We have corrected the mistake now. Thanks for taking the time to point that out.

  39. noway

    aggregation an composition in a class diagramm are shown by the diamond on the aggregate calss side . It means the “Library” calss will have the diamond and not the “Books”. Very common mistake, most if the beginners make.

    thanks noway

Leave a comment


two × two =

Back to top