UML Class Diagram Comprehensive Notation Guide

Introduction

UML (Unified Modeling Language) class diagrams are essential tools in software engineering for visualizing the static structure of a system. They illustrate the system’s classes, attributes, methods, and the relationships between these elements. This guide provides a comprehensive overview of UML class diagram notations, using a detailed example to explain key concepts.

Key Concepts in UML Class Diagrams

  1. Class:
    • Represents a blueprint for creating objects.
    • Notation: A rectangle divided into three parts: class name, attributes, and methods.
    • A class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system’s classes, their attributes, operations (or methods), and the relationships among objects.
  2. Attributes:
    • Represent the properties or data fields of a class.
    • Notation: Listed in the second compartment of the class rectangle.
    • In object-oriented design, there is a notation of visibility for attributes and operations. UML identifies four types of visibility: public, protected, private, and package.
  3. Methods (Operations):
    • Represent the behaviors or functions that a class can perform.
    • Notation: Listed in the third compartment of the class rectangle.
  4. Visibility:
    • Indicates the accessibility of attributes and methods.
    • Notations:
      • + Public
      • - Private
      • # Protected
      • ~ Package
  5. Relationships:
    • Association: A general relationship between classes.
      • Notation: A solid line connecting two classes.
      • The UML representation of an association is a line connecting the two associated classes. At each end of the line there is optional notation. For example, we can indicate, using an arrowhead that the pointy end is visible from the arrow tail.
    • Aggregation: A “whole-part” relationship where the part can exist independently of the whole.
      • Notation: A hollow diamond at the aggregate end.
      • Furthermore, there is hardly a difference between aggregations and associations during implementation, and the diagram may skip aggregation relations altogether. Aggregation can occur when a class is a collection or container of other classes, but the contained classes do not have a strong lifecycle dependency on the container. The contents of the container still exist when the container is destroyed. In UML, it is graphically represented as a hollow diamond shape on the containing class with a single line that connects it to the contained class.
    • Composition: A stronger form of aggregation where the part cannot exist independently of the whole.
      • Notation: A filled diamond at the composite end.
    • Inheritance (Generalization): A relationship where one class inherits attributes and methods from another.
      • Notation: A hollow triangle pointing to the superclass.
      • Generalization can only be shown on class diagrams and on use case diagrams. In UML modelling, a realization relationship is a relationship between two model elements, in which one model element (the client) realizes (implements or executes) the behavior that the other model element (the supplier) specifies.
    • Dependency: A relationship where one class uses another.
      • Notation: A dashed line with an arrow pointing from the dependent class to the independent class.
  6. Multiplicity:
    • Indicates the number of instances of one class related to one instance of another class.
    • Notation: Numbers or ranges placed near the ends of association lines.
    • Multiplicity – 1. A specification of the number of possible occurrences of a property, or the number of allowable elements that may participate in a given relationship. In UML 1.x, it was also possible to have a discrete list of values, but this was eliminated in UML 2.0.
  7. Roles:
    • Indicate the part played by an instance of a class in a relationship.
    • Notation: Text near the association line.

Example Diagram Interpretation

What is a Class Diagram?. In software engineering, a class… | by Katie  Holland | Medium

Let’s interpret the provided UML class diagram step by step:

  1. Classes:
    • Line: Represents a telephone line with attributes busy (boolean) and id (int), and methods offHook() and onHook().
    • Telephone: Represents a telephone with attributes hook (boolean), connection (int), and methods offHook()onHook()dial()setCallerId(), and setAnsMachine().
    • Ringer: Represents a ringer with attributes status (boolean) and methods ring() and reset().
    • Caller Id: Represents a caller ID with attributes id (int) and display (int), and methods set() and reset().
    • Answering Machine: Represents an answering machine with attributes status (boolean) and methods set()reset()playback(), and record().
    • Message: Represents a message with attribute content (AudioStream).
  2. Relationships:
    • Association:
      • Between Line and Telephone: Indicates that a telephone line is connected to a telephone.
      • Between Telephone and Ringer: Indicates that a telephone is associated with a ringer.
      • Between Telephone and Caller Id: Indicates that a telephone is associated with a caller ID.
      • Between Telephone and Answering Machine: Indicates that a telephone is associated with an answering machine.
    • Composition:
      • Between Answering Machine and Message: Indicates that an answering machine is composed of messages.
  3. Multiplicity:
    • Between Line and Telephone: A line can be connected to zero or one telephone (0..1).
    • Between Telephone and RingerCaller IdAnswering Machine: A telephone can be associated with one ringer, one caller ID, and one answering machine (1).
    • Between Answering Machine and Message: An answering machine can have multiple messages (0..*).
  4. Roles:
    • connectedPhones: Indicates the role of telephones connected to a line.

Table: Summary of Notations

Notation Description Example
Class Represents a blueprint for objects. LineTelephone
Attribute Represents properties of a class. busy: boolean
Method (Operation) Represents behaviors of a class. offHook()
Visibility Indicates accessibility of attributes and methods. + Public, - Private
Association A general relationship between classes. Solid line between Line and Telephone
Aggregation A “whole-part” relationship. Hollow diamond
Composition A stronger form of aggregation. Filled diamond between Answering Machine and Message
Inheritance One class inherits from another. Hollow triangle
Dependency One class uses another. Dashed line with arrow
Multiplicity Number of instances in a relationship. 0..110..*
Role Part played by an instance in a relationship. connectedPhones

Conclusion

UML class diagrams are powerful tools for visualizing the structure of object-oriented systems. Understanding the notations and relationships is crucial for effective system design and communication. By following this guide and interpreting the example diagram, you can gain a comprehensive understanding of UML class diagrams and their applications in software engineering.

References

Wikipedia

  1. Class Diagram:
  2. Unified Modeling Language:
  3. Object Diagram:
  4. Component Diagram:
  5. UML State Machine:
  6. Activity Diagram:
  7. Sequence Diagram:
  8. Executable UML:
  9. Glossary of Unified Modeling Language terms:

OMG (Object Management Group)

  1. UML Specifications:
    • OMG UML Specifications
    • Description: Official specifications for UML, including class diagrams and their notations.
  2. Class Diagram Keyword:
  3. Diagram Interchange:
  4. UML Certifications:

Visual Paradigm

  1. UML Class Diagram Tutorial:
  2. What is Class Diagram?:
  3. UML Practical Guide:
  4. Understanding Profile Diagrams in UML:
  5. Understanding UML Component Diagrams:
  6. Six Types of Relationships in UML Class Diagrams:
  7. UML Association vs Aggregation vs Composition:
  8. All You Need to Know about State Diagrams:
  9. UML – A Comprehensive Guide:

Cybermedian

  1. Comprehensive Guide to the 14 UML Diagram Types:
  2. A Comprehensive Guide to UML Class Diagram:
  3. UML Diagrams: A Comprehensive Guide:
  4. A Comprehensive Guide to 14 Types of UML Diagram:
  5. Understanding UML Timing Diagrams: A Comprehensive Guide:
  6. Comprehensive Tutorial on State Machine Diagrams:
  7. Learning by Example: UML State Machine Diagrams:
  8. Comprehensive Tutorial on Use Case Diagrams:
  9. A Comprehensive Guide to Understanding and Implementing Unified Modeling Language in Software Development:

ArchiMetric

  1. A Comprehensive Tutorial on UML Deployment Diagram:
  2. Navigating UML: An Overview of the 14 Diagram Types and Their Relevance in Agile Environments:
  3. What is UML?:
    • What is UML? – ArchiMetric
    • Description: Explains the Unified Modeling Language (UML) and its role in software development, including class diagrams and their notations.
  4. Introduction to UML Diagrams in Visual Paradigm:
  5. Comprehensive Tutorial on Deployment Diagrams with Visual Paradigm:
  6. What is Activity Diagram:
  7. Comprehensive Guide on Use Cases and the Concepts of Extend and Include:
  8. Top Visual Paradigm Tools for Business Process Modeling:
  9. 什么是类图? (What is Class Diagram?):
  10. Understanding ArchiMate Key Concepts: A Comprehensive Guide:

These references provide a thorough understanding of UML class diagrams, their components, notations, and relationships, as well as their applications in software engineering.

These references provide a thorough understanding of UML class diagrams, their components, notations, and relationships, as well as their applications in software engineering.