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 25, 2025
Sign in / Join
  • Contact Us
  • Our Team
Facebook
Instagram
Twitter
Vimeo
Youtube
Logo
  • Home
  • News
    • News

      Global FileFix Phishing Campaign Spreads StealC Malware via File Explorer Trick by Husain Parvez

      23 September 2025
      News

      CrowdStrike and Meta Launch CyberSOCEval to Benchmark AI in Real-World Cyber Defense by Husain Parvez

      23 September 2025
      News

      “Safety Ahead of Privacy”: OpenAI to Add ID Verification for ChatGPT Users by Paige Henley

      23 September 2025
      News

      Shai-Hulud Worm Compromises 180+ NPM Packages: Steals Secrets via GitHub Actions by Husain Parvez

      19 September 2025
      News

      Ukrainian Networks Linked to Large-Scale Brute-Force Attacks on VPN and RDP Systems by Husain Parvez

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

      Getting Started with langgraph-up-react: A Practical LangGraph Template

      14 September 2025
      Big data

      LangChain vs LangGraph: A Developer’s Guide to Choosing Your AI Frameworks

      10 September 2025
      Big data

      Nano Banana + Milvus: Turning Hype into Enterprise-Ready Multimodal RAG

      6 September 2025
      Big data

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

      30 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

      YouTube view counts are plummeting and these small changes might be behind it

      24 September 2025
      Android

      Google’s new Mixboard wants to be Pinterest but is an AI mishmash

      24 September 2025
      Android

      Google’s AI Search Live is out, and it’s the conversational upgrade we’ve been waiting for

      24 September 2025
      Android

      Qualcomm’s new Snapdragon 8 Elite Gen 5 claims to be the ‘world’s fastest’ mobile chip

      24 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

      How to Install a VPN on FRITZ!Box: Complete 2025 Guide by Husain Parvez

      24 September 2025
      Guest Blogs

      What Is IPv6? Everything You Need to Know in 2025 by Husain Parvez

      22 September 2025
      Guest Blogs

      How to Watch Champions League From Anywhere in 2025 by Toma Novakovic

      22 September 2025

      LEAVE A REPLY Cancel reply

      Log in to leave a comment

      Most Popular

      YouTube view counts are plummeting and these small changes might be behind it

      24 September 2025

      Google’s new Mixboard wants to be Pinterest but is an AI mishmash

      24 September 2025

      Google’s AI Search Live is out, and it’s the conversational upgrade we’ve been waiting for

      24 September 2025

      Qualcomm’s new Snapdragon 8 Elite Gen 5 claims to be the ‘world’s fastest’ mobile chip

      24 September 2025
      Load more
      Algomaster
      Algomaster
      202 POSTS0 COMMENTS
      https://blog.algomaster.io
      Calisto Chipfumbu
      Calisto Chipfumbu
      6693 POSTS0 COMMENTS
      http://cchipfumbu@gmail.com
      Dominic
      Dominic
      32319 POSTS0 COMMENTS
      http://wardslaus.com
      Milvus
      Milvus
      84 POSTS0 COMMENTS
      https://milvus.io/
      Nango Kala
      Nango Kala
      6680 POSTS0 COMMENTS
      neverop
      neverop
      0 POSTS0 COMMENTS
      https://geeksforgeeks.org
      Nicole Veronica
      Nicole Veronica
      11852 POSTS0 COMMENTS
      Nokonwaba Nkukhwana
      Nokonwaba Nkukhwana
      11910 POSTS0 COMMENTS
      Safety Detectives
      Safety Detectives
      2654 POSTS0 COMMENTS
      https://www.safetydetectives.com/
      Shaida Kate Naidoo
      Shaida Kate Naidoo
      6794 POSTS0 COMMENTS
      Ted Musemwa
      Ted Musemwa
      7070 POSTS0 COMMENTS
      Thapelo Manthata
      Thapelo Manthata
      6752 POSTS0 COMMENTS
      Umr Jansen
      Umr Jansen
      6761 POSTS0 COMMENTS

      EDITOR PICKS

      YouTube view counts are plummeting and these small changes might be behind it

      24 September 2025

      Google’s new Mixboard wants to be Pinterest but is an AI mishmash

      24 September 2025

      Google’s AI Search Live is out, and it’s the conversational upgrade we’ve been waiting for

      24 September 2025

      POPULAR POSTS

      YouTube view counts are plummeting and these small changes might be behind it

      24 September 2025

      Google’s new Mixboard wants to be Pinterest but is an AI mishmash

      24 September 2025

      Google’s AI Search Live is out, and it’s the conversational upgrade we’ve been waiting for

      24 September 2025

      POPULAR CATEGORY

      • Languages45985
      • Data Modelling & AI17569
      • Java15156
      • Android14530
      • Mobile12983
      • Javascript12713
      • Guest Blogs12704
      • 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