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
- 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 objects123.
- Attributes:
- Methods (Operations):
- Represent the behaviors or functions that a class can perform.
- Notation: Listed in the third compartment of the class rectangle.
- Visibility:
- Indicates the accessibility of attributes and methods.
- Notations:
+
Public-
Private#
Protected~
Package
- 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 tail1.
- 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 class1.
- 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) specifies1.
- Dependency: A relationship where one class uses another.
- Notation: A dashed line with an arrow pointing from the dependent class to the independent class.
- Association: A general relationship between classes.
- 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.05.
- Roles:
- Indicate the part played by an instance of a class in a relationship.
- Notation: Text near the association line.
Example Diagram Interpretation
Let’s interpret the provided UML class diagram step by step:
- Classes:
- Line: Represents a telephone line with attributes
busy
(boolean) andid
(int), and methodsoffHook()
andonHook()
. - Telephone: Represents a telephone with attributes
hook
(boolean),connection
(int), and methodsoffHook()
,onHook()
,dial()
,setCallerId()
, andsetAnsMachine()
. - Ringer: Represents a ringer with attributes
status
(boolean) and methodsring()
andreset()
. - Caller Id: Represents a caller ID with attributes
id
(int) anddisplay
(int), and methodsset()
andreset()
. - Answering Machine: Represents an answering machine with attributes
status
(boolean) and methodsset()
,reset()
,playback()
, andrecord()
. - Message: Represents a message with attribute
content
(AudioStream).
- Line: Represents a telephone line with attributes
- Relationships:
- Association:
- Between
Line
andTelephone
: Indicates that a telephone line is connected to a telephone. - Between
Telephone
andRinger
: Indicates that a telephone is associated with a ringer. - Between
Telephone
andCaller Id
: Indicates that a telephone is associated with a caller ID. - Between
Telephone
andAnswering Machine
: Indicates that a telephone is associated with an answering machine.
- Between
- Composition:
- Between
Answering Machine
andMessage
: Indicates that an answering machine is composed of messages.
- Between
- Association:
- Multiplicity:
- Between
Line
andTelephone
: A line can be connected to zero or one telephone (0..1). - Between
Telephone
andRinger
,Caller Id
,Answering Machine
: A telephone can be associated with one ringer, one caller ID, and one answering machine (1). - Between
Answering Machine
andMessage
: An answering machine can have multiple messages (0..*).
- Between
- Roles:
connectedPhones
: Indicates the role of telephones connected to a line.
Table: Summary of Notations
Notation | Description | Example |
---|---|---|
Class | Represents a blueprint for objects. | Line , Telephone |
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..1 , 1 , 0..* |
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
- Class Diagram:
- Class diagram – Wikipedia
- Description: Provides an overview of class diagrams, their components, and notations in UML.
- Unified Modeling Language:
- Unified Modeling Language – Wikipedia
- Description: Covers the history, types, and uses of UML, including class diagrams.
- Object Diagram:
- Object diagram – Wikipedia
- Description: Explains object diagrams, which are instances of class diagrams, and their notations.
- Component Diagram:
- Component diagram – Wikipedia
- Description: Describes component diagrams and their relationship with class diagrams in UML.
- UML State Machine:
- UML state machine – Wikipedia
- Description: Discusses state machines in UML and their graphical notations.
- Activity Diagram:
- Activity diagram – Wikipedia
- Description: Covers activity diagrams in UML and their evolution from state diagrams.
- Sequence Diagram:
- Sequence diagram – Wikipedia
- Description: Discusses sequence diagrams and their role in UML.
- Executable UML:
- Executable UML – Wikipedia
- Description: Covers Executable UML and its class diagram notations.
- Glossary of Unified Modeling Language terms:
- Glossary of Unified Modeling Language terms – Wikipedia
- Description: Provides definitions for UML terms, including class diagram components.
OMG (Object Management Group)
- UML Specifications:
- OMG UML Specifications
- Description: Official specifications for UML, including class diagrams and their notations.
- Class Diagram Keyword:
- Class Diagram Keyword – OMG
- Description: Provides a summary of OMG specifications related to class diagrams.
- Diagram Interchange:
- Diagram Interchange – OMG
- Description: Specifications for the interchange of UML diagrams, including class diagrams.
- UML Certifications:
- UML Certifications – OMG
- Description: Information on UML certifications, including class diagram proficiency.
Visual Paradigm
- UML Class Diagram Tutorial:
- UML Class Diagram Tutorial – Visual Paradigm
- Description: A comprehensive tutorial on UML class diagrams, their components, and notations.
- What is Class Diagram?:
- What is Class Diagram? – Visual Paradigm
- Description: An overview of class diagrams and their role in UML.
- UML Practical Guide:
- UML Practical Guide – Visual Paradigm
- Description: A practical guide to UML, including class diagrams and their applications.
- Understanding Profile Diagrams in UML:
- Understanding Profile Diagrams in UML – Visual Paradigm
- Description: Explains profile diagrams and their use in UML class diagrams.
- Understanding UML Component Diagrams:
- Understanding UML Component Diagrams – Visual Paradigm
- Description: A comprehensive guide to UML component diagrams and their relationship with class diagrams.
- Six Types of Relationships in UML Class Diagrams:
- Six Types of Relationships in UML Class Diagrams – Visual Paradigm
- Description: Explains the six types of relationships in UML class diagrams.
- UML Association vs Aggregation vs Composition:
- UML Association vs Aggregation vs Composition – Visual Paradigm
- Description: Discusses the differences between association, aggregation, and composition in UML class diagrams.
- All You Need to Know about State Diagrams:
- All You Need to Know about State Diagrams – Visual Paradigm
- Description: Covers state diagrams and their notations in UML.
- UML – A Comprehensive Guide:
- UML – A Comprehensive Guide – Visual Paradigm
- Description: A comprehensive guide to UML, including class diagrams and their components.
Cybermedian
- Comprehensive Guide to the 14 UML Diagram Types:
- Comprehensive Guide to the 14 UML Diagram Types – Cybermedian
- Description: Provides an overview of all 14 UML diagram types, including class diagrams.
- A Comprehensive Guide to UML Class Diagram:
- A Comprehensive Guide to UML Class Diagram – Cybermedian
- Description: A detailed guide to UML class diagrams, their components, and notations.
- UML Diagrams: A Comprehensive Guide:
- UML Diagrams: A Comprehensive Guide – Cybermedian
- Description: Covers various UML diagrams, including class diagrams and their uses.
- A Comprehensive Guide to 14 Types of UML Diagram:
- A Comprehensive Guide to 14 Types of UML Diagram – Cybermedian
- Description: Provides a comprehensive overview of all UML diagram types, including class diagrams.
- Understanding UML Timing Diagrams: A Comprehensive Guide:
- Understanding UML Timing Diagrams: A Comprehensive Guide – Cybermedian
- Description: Explains UML timing diagrams and their relationship with class diagrams.
- Comprehensive Tutorial on State Machine Diagrams:
- Comprehensive Tutorial on State Machine Diagrams – Cybermedian
- Description: A tutorial on state machine diagrams in UML and their notations.
- Learning by Example: UML State Machine Diagrams:
- Learning by Example: UML State Machine Diagrams – Cybermedian
- Description: Provides examples of UML state machine diagrams and their components.
- Comprehensive Tutorial on Use Case Diagrams:
- Comprehensive Tutorial on Use Case Diagrams – Cybermedian
- Description: A tutorial on use case diagrams in UML and their relationship with class diagrams.
- A Comprehensive Guide to Understanding and Implementing Unified Modeling Language in Software Development:
- A Comprehensive Guide to Understanding and Implementing Unified Modeling Language in Software Development – Cybermedian
- Description: A comprehensive guide to understanding and implementing UML in software development, including class diagrams.
ArchiMetric
- A Comprehensive Tutorial on UML Deployment Diagram:
- A Comprehensive Tutorial on UML Deployment Diagram – ArchiMetric
- Description: Provides a comprehensive guide to understanding, creating, and interpreting UML Deployment Diagrams, including basic UML notation and diagrams such as Use Case, Class, Sequence, and Activity Diagrams.
- Navigating UML: An Overview of the 14 Diagram Types and Their Relevance in Agile Environments:
- Navigating UML: An Overview of the 14 Diagram Types and Their Relevance in Agile Environments – ArchiMetric
- Description: Discusses the 14 types of UML diagrams, including class diagrams, and their relevance in agile environments.
- 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.
- Introduction to UML Diagrams in Visual Paradigm:
- Introduction to UML Diagrams in Visual Paradigm – ArchiMetric
- Description: Introduces the 14 types of UML diagrams available in Visual Paradigm, with a focus on class diagrams and their importance in object-oriented design.
- Comprehensive Tutorial on Deployment Diagrams with Visual Paradigm:
- Comprehensive Tutorial on Deployment Diagrams with Visual Paradigm – ArchiMetric
- Description: Provides a tutorial on deployment diagrams and their integration with other UML diagrams, such as class diagrams.
- What is Activity Diagram:
- What is Activity Diagram – ArchiMetric
- Description: Explains activity diagrams and their notations, including object notations in UML activity diagrams.
- Comprehensive Guide on Use Cases and the Concepts of Extend and Include:
- Comprehensive Guide on Use Cases and the Concepts of Extend and Include – ArchiMetric
- Description: Discusses use case diagrams and their relationship with class diagrams in UML.
- Top Visual Paradigm Tools for Business Process Modeling:
- Top Visual Paradigm Tools for Business Process Modeling – ArchiMetric
- Description: Highlights Visual Paradigm’s support for various UML diagrams, including class diagrams, and its advanced modeling capabilities.
- 什么是类图? (What is Class Diagram?):
- 什么是类图? (What is Class Diagram?) – ArchiMetric
- Description: Provides an overview of class diagrams in UML, including their components and notations.
- Understanding ArchiMate Key Concepts: A Comprehensive Guide:
- Understanding ArchiMate Key Concepts: A Comprehensive Guide – ArchiMetric
- Description: Explains ArchiMate and its integration with UML, including class diagrams and their notations.
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.