Facebook Instagram Twitter Vimeo Youtube
Sign in
  • Home
  • About
  • Team
  • Buy now!
Sign in
Welcome!Log into your account
Forgot your password?
Privacy Policy
Password recovery
Recover your password
Search
Logo
Sign in
Welcome! Log into your account
Forgot your password? Get help
Privacy Policy
Password recovery
Recover your password
A password will be e-mailed to you.
Thursday, September 4, 2025
Sign in / Join
  • Contact Us
  • Our Team
Facebook
Instagram
Twitter
Vimeo
Youtube
Logo
  • Home
  • News
    • News

      Anthropic Confirms Claude AI Was Weaponized in Major Cyberattacks by Husain Parvez

      3 September 2025
      News

      Over 30,000 Malicious IPs Target Microsoft Remote Desktop in Global Surge by Husain Parvez

      31 August 2025
      News

      Cyber Threat-Sharing Law Nears Expiration: Experts Warn of Risks by Husain Parvez

      31 August 2025
      News

      North Korean Hacking Tools Leak Online, Including Advanced Linux Rootkit by Paige Henley

      28 August 2025
      News

      iiNet Cyberattack Exposes Data of 280,000 Customers by Husain Parvez

      28 August 2025
  • Data Modelling & AI
    • AllBig dataBusiness AnalyticsData ScienceData Structure & AlgorithmDatabasesVector DatabaseDeep LearningEthical HackingGenerative AIMachine Learning
      Big data

      LangExtract + Milvus: A Practical Guide to Building a Hybrid Document Processing and Search System

      30 August 2025
      Big data

      Stop Your AI Assistant from Writing Outdated Code with Milvus SDK Code Helper

      26 August 2025
      Big data

      A Practical Guide for Choosing the Right Vector Database for Your AI Applications

      26 August 2025
      Big data

      Why I’m Against Claude Code’s Grep-Only Retrieval? It Just Burns Too Many Tokens

      26 August 2025
    • Big data
    • Business Analytics
    • Databases
    • Data Structure & Algorithm
    • Data Science
    • Deep Learning
    • Ethical Hacking
    • Generative AI
    • Machine Learning
    • Security & Testing
  • Mobile
    • AllAndroidIOS
      Android

      The Samsung Health app now puts a licensed doctor right in your pocket

      3 September 2025
      Android

      Google’s NotebookLM is giving Audio Overviews new personalities

      3 September 2025
      Android

      MediaTek’s next flagship chip may give future Android phones faster cores and a beefed-up NPU

      3 September 2025
      Android

      Google Maps navigation on Pixel and Wear OS watches just got a lot easier

      3 September 2025
    • Android
    • IOS
  • Languages
    • AllAjaxAngularDynamic ProgrammingGolangJavaJavascriptPhpPythonReactVue
      Languages

      Working with Titles and Heading – Python docx Module

      25 June 2025
      Languages

      Creating a Receipt Calculator using Python

      25 June 2025
      Languages

      One Liner for Python if-elif-else Statements

      25 June 2025
      Languages

      Add Years to datetime Object in Python

      25 June 2025
    • Java
    • Python
  • Guest Blogs
  • Discussion
  • Our Team
HomeData Modelling & AIBig dataUML Class Diagram Explained with Examples
Big dataGuest Blogs

UML Class Diagram Explained with Examples

Algomaster
By Algomaster
15 June 2025
0
0
Share
Facebook
Twitter
Pinterest
WhatsApp

    UML Class Diagram Explained with Examples

    #15 Object Oriented Design – UML Class Diagram

    Ashish Pratap Singh's avatar

    Ashish Pratap Singh
    Jun 09, 2024

    Unified Modeling Language (UML) is a standard way to visualize the design of a software system.

    Among the many diagrams offered by UML, class diagrams are perhaps the most widely used.

    UML class diagram provides a static view of an object oriented system, showcasing its classes, attributes, methods, and the relationships among objects.

    In this article, we will explore the building blocks of UML class diagram, how to represent them, different types of class relationships and provide real-world examples for each representation.


    If you’re finding this newsletter valuable and want to deepen your learning, consider becoming a paid subscriber.

    As a paid subscriber, you’ll receive an exclusive deep-dive article every week, access to a structured System Design Resource (100+ topics and interview questions), and other premium perks.

    Unlock Full Access


    Building Blocks of UML Class Diagrams

    A UML class diagram consists of the following building blocks:

    1. Class

    A class is a blueprint or template that defines the properties and behavior of an object.

    Represented as rectangles, classes are divided into three compartments:

    • Name (top compartment): The unique identifier of the class (e.g., BankAccount).

    • Attributes (middle compartment): The properties or data associated with the class (e.g., accountNumber, balance).

    • Operations (bottom compartment): The actions or methods that can be performed by objects of the class (e.g., deposit(), updateBalance()).

    Visibility Markers: Visibility markers indicate the accessibility of attributes and methods within a class.

    • + (Public): The attribute or method is accessible from any class.

    • - (Private): The attribute or method is only accessible within the same class.

    • # (Protected): The attribute or method is accessible within the same class and its subclasses.

    • ~ (Package): The attribute or method is accessible within the same package.

    2. Attributes

    Attributes in a UML class diagram represent the properties or data fields of a class.

    Attributes are typically written in the format:

    visibility name: type [multiplicity] = defaultValue

    Name: The name of the attribute.

    Type: The data type of the attribute.

    Multiplicity: (Optional) Indicates how many instances of the type are allowed.

    Default Value: (Optional) The initial value of the attribute.

    Example:

    3. Methods

    Methods (or operations) in a UML class diagram represent the functions or behaviors that a class can perform.

    Methods are typically written in the format:

    visibility name(parameterList): returnType
    • Name: The name of the method.

    • Parameter List: A comma-separated list of parameters, each specified as name: type.

    • Return Type: The data type returned by the method.

    Example:

    4. Interfaces

    An interface defines a contract for classes that implement it. It specifies a set of methods that the implementing classes must provide.

    Interfaces are depicted as a class rectangle with the keyword «interface» above the interface name. Methods in interfaces are abstract by nature, so they are usually shown without any implementation details.

    Example:

    5. Abstract Class

    An abstract class is a class that cannot be instantiated (you can’t create objects directly from it).

    It serves as a blueprint for other classes (subclasses) that inherit from it.

    An abstract class in UML is represented with the class name in italics and the keyword «abstract» above the class name. Abstract methods within the class are also typically shown in italics.

    Example:

    6. Enumeration

    An enumeration is a data type that defines a set of named values (e.g., colors, days of the week).

    Enumerations, or enums, are represented with the keyword «enumeration» above the enumeration name. The values of the enumeration are listed within the class box.

    Example:

    7. Multiplicity

    Multiplicity specifies the number of instances of one class that can be related to a single instance of another class.

    It is represented by a number or a range of numbers near the end of an association line.

    Common multiplicities include: 1 (exactly one), 0..1 (zero or one), * (zero or more), 1..* (one or more).

    Share

    Relationships in UML Class Diagrams

    There are six main types of relationships between classes: association, aggregation, composition, inheritance, implementation and dependency.

    The arrows for the six relationships are as follows:

    1. Association

    Association represents a “uses-a” relationship between two classes where one class uses or interacts with the other.

    Example: A Student class is associated with a Course class, as a student can enroll in multiple courses.

    2. Aggregation

    Aggregation represents a “has-a” relationship where one class (the whole) contains another class (the part), but the contained class can exist independently.

    Example: A Car class has an Engine class but the Engine class can exist without the Car class.

    3. Composition

    Composition represents a strong “has-a” relationship where the part cannot exist without the whole. If the whole is destroyed, the parts are also destroyed.

    Example: A House class is composed of Room class but the Room class can not exist without the House class.

    4. Inheritance

    Inheritance (or Generalization) represents an “is-a” relationship where one class (subclass) inherits the attributes and methods of another class (superclass).

    Example: A Dog class and a Cat class inherit from an Animal class, as both dogs and cats are animals.

    5. Realization (Implementation)

    Realization or implementation represents a relationship between a class and an interface, where the class implements the methods declared in the interface.

    Example: A Rectangle class and a Circle class implement the Shape interface, which declares a getArea() method.

    6. Dependency

    Dependency represents a “uses” relationship where a change in one class (the supplier) may affect the other class (the client).

    Example: A Customer class uses an Order class to place order.

    Combined Example

    Here’s a comprehensive example that includes various types of relationships:

    The relationships between the classes are as follows:

    • Inheritance: Dog and Cat inherit from Animal.

    • Realization/Implementation: Dog and Cat implement the Pet interface.

    • Aggregation: Person has an aggregation relationship with Pet, indicating that a person can have multiple pets.

    • Composition: Person has a composition relationship with Address, indicating that an address cannot exist without a person.

    • Association: Person has an association relationship with Phone, indicating that a person can have multiple phone numbers.

    • Dependency: Phone depends on the PhoneType enumeration for the phoneType attribute.

    Among the six types of relationships, the code structure of composition, aggregation, and association is the same, and it can be understood from the strength of the relationship. The order from strong to weak is: inheritance → implementation → composition → aggregation → association → dependency


    Thank you for reading!

    If you found it valuable, hit a like ❤️ and consider subscribing for more such content every week.

    If you have any questions or suggestions, leave a comment.

    This post is public so feel free to share it.

    Share


    P.S. If you’re finding this newsletter helpful and want to get even more value, consider becoming a paid subscriber.

    As a paid subscriber, you’ll receive an exclusive deep dive every week, access to a comprehensive system design learning resource , and other premium perks.

    Get full access to AlgoMaster

    There are group discounts, gift options, and referral bonuses available.


    Checkout my Youtube channel for more in-depth content.

    Follow me on LinkedIn, X and Medium to stay updated.

    Checkout my GitHub repositories for free interview preparation resources.

    I hope you have a lovely day!

    See you soon,
    Ashish

    Share
    Facebook
    Twitter
    Pinterest
    WhatsApp
      Previous article
      Rate Limiting Algorithms Explained with Code
      Next article
      How to Answer a LLD Interview Problem
      Algomaster
      Algomasterhttps://blog.algomaster.io
      RELATED ARTICLES
      Guest Blogs

      7 Best 123Movies Alternatives in 2025: Free & Safe Sites by Ivan Stevanovic

      3 September 2025
      Guest Blogs

      Interview with Tyson Garrett – CTO of TrustOnCloud – Making Cloud Threat Modeling Executable by Shauli Zacks

      2 September 2025
      Big data

      LangExtract + Milvus: A Practical Guide to Building a Hybrid Document Processing and Search System

      30 August 2025

      LEAVE A REPLY Cancel reply

      Log in to leave a comment

      Most Popular

      The Samsung Health app now puts a licensed doctor right in your pocket

      3 September 2025

      Google’s NotebookLM is giving Audio Overviews new personalities

      3 September 2025

      MediaTek’s next flagship chip may give future Android phones faster cores and a beefed-up NPU

      3 September 2025

      Google Maps navigation on Pixel and Wear OS watches just got a lot easier

      3 September 2025
      Load more
      Algomaster
      Algomaster
      202 POSTS0 COMMENTS
      https://blog.algomaster.io
      Calisto Chipfumbu
      Calisto Chipfumbu
      6637 POSTS0 COMMENTS
      http://cchipfumbu@gmail.com
      Dominic
      Dominic
      32260 POSTS0 COMMENTS
      http://wardslaus.com
      Milvus
      Milvus
      81 POSTS0 COMMENTS
      https://milvus.io/
      Nango Kala
      Nango Kala
      6625 POSTS0 COMMENTS
      neverop
      neverop
      0 POSTS0 COMMENTS
      https://geeksforgeeks.org
      Nicole Veronica
      Nicole Veronica
      11795 POSTS0 COMMENTS
      Nokonwaba Nkukhwana
      Nokonwaba Nkukhwana
      11855 POSTS0 COMMENTS
      Safety Detectives
      Safety Detectives
      2594 POSTS0 COMMENTS
      https://www.safetydetectives.com/
      Shaida Kate Naidoo
      Shaida Kate Naidoo
      6746 POSTS0 COMMENTS
      Ted Musemwa
      Ted Musemwa
      7023 POSTS0 COMMENTS
      Thapelo Manthata
      Thapelo Manthata
      6694 POSTS0 COMMENTS
      Umr Jansen
      Umr Jansen
      6714 POSTS0 COMMENTS

      EDITOR PICKS

      The Samsung Health app now puts a licensed doctor right in your pocket

      3 September 2025

      Google’s NotebookLM is giving Audio Overviews new personalities

      3 September 2025

      MediaTek’s next flagship chip may give future Android phones faster cores and a beefed-up NPU

      3 September 2025

      POPULAR POSTS

      The Samsung Health app now puts a licensed doctor right in your pocket

      3 September 2025

      Google’s NotebookLM is giving Audio Overviews new personalities

      3 September 2025

      MediaTek’s next flagship chip may give future Android phones faster cores and a beefed-up NPU

      3 September 2025

      POPULAR CATEGORY

      • Languages45985
      • Data Modelling & AI17566
      • Java15156
      • Android14048
      • Mobile12983
      • Javascript12713
      • Guest Blogs12669
      • Data Structure & Algorithm10077
      Logo

      ABOUT US

      We provide you with the latest breaking news and videos straight from the technology industry.

      Contact us: hello@geeksforgeeks.org

      FOLLOW US

      Blogger
      Facebook
      Flickr
      Instagram
      VKontakte

      © NeverOpen 2022

      • Home
      • News
      • Data Modelling & AI
      • Mobile
      • Languages
      • Guest Blogs
      • Discussion
      • Our Team