UML Diagrams and Models - EduardoMSU/OOP-2143 GitHub Wiki
UML Diagrams and Models
UML (Unified Modeling Language) is a standardized modeling language used to visually represent the design and structure of a system. In Object-Oriented Programming (OOP), UML diagrams help to model the relationships, interactions, and behavior of objects within a system. There are various types of UML diagrams that serve different purposes, such as Class Diagrams, Sequence Diagrams, Use Case Diagrams, and others.
Types of UML Diagrams
Diagram Type | Description | Purpose |
---|---|---|
Class Diagram | Describes the static structure of a system by showing its classes, their attributes, methods, and relationships. | System structure |
Object Diagram | Shows a snapshot of instances of classes at a particular moment in time. | Object state |
Use Case Diagram | Represents the functional requirements of a system, showing actors and use cases. | Requirement analysis |
Sequence Diagram | Describes how objects interact in a particular sequence, showing messages exchanged between objects. | Interaction behavior |
Activity Diagram | Represents the workflow of a system or a process, illustrating the flow of control between activities. | Workflow modeling |
State Diagram | Shows the states of an object and the transitions between those states. | State transitions |
Component Diagram | Illustrates how components (like classes, modules, or libraries) are organized and interact. | System architecture |
Deployment Diagram | Describes the physical deployment of artifacts (e.g., software and hardware) in a system. | Hardware/software architecture |
1. Class Diagram
Definition:
A Class Diagram shows the static structure of a system by displaying its classes, their attributes, methods, and relationships. It is one of the most commonly used diagrams in object-oriented design.
Key Elements:
- Classes: Represented by rectangles with three sections (name, attributes, and methods).
- Attributes: Represent the properties or data members of the class.
- Methods: Represent the operations or behaviors the class can perform.
- Relationships:
- Association: A relationship where one class uses or interacts with another (e.g., aggregation, composition).
- Inheritance (Generalization): A relationship where one class (subclass) inherits properties and behaviors from another (superclass).
- Dependency: A relationship where one class depends on another.
- Aggregation: A special form of association, representing a "whole-part" relationship where the part can exist independently.
- Composition: A stronger form of aggregation where the part cannot exist without the whole.
Example of a Class Diagram
+-------------------+ +---------------------+
| Person |<>---------| Address |
+-------------------+ +---------------------+
| - name: string | | - street: string |
| - age: int | | - city: string |
+-------------------+ +---------------------+
| + getName(): string | | + getFullAddress(): string |
+-------------------+ +---------------------+