Class Diagram (UML) – Classes, Attributes, Methods, Inheritance, Association, Aggregation & Composition
This article is a conceptual explanation of class diagrams – including exam questions and tags.
In a Nutshell
Class diagrams show the structure of a software system through classes, their attributes, methods, and the relationships between them – a central component of object-oriented modeling with UML.
Compact Technical Description
A class diagram visualizes the static structure of an object-oriented system. It shows classes with their attributes and methods as well as relationships such as association, inheritance, aggregation, and composition. Each class is represented as a rectangle with three sections: name, attributes, methods. Visibility levels (+ public, - private, # protected) and data types are explicitly specified. UML class diagrams are important for the design phase because they depict the later object-oriented design and reveal potential problems early on.
Exam-Relevant Key Points
- Component of UML for modeling system structure
- Contains classes with attributes and methods
- Represents relationships such as inheritance, association, aggregation, composition
- Allows visibility levels and data types (IHK-relevant)
- Supports object-oriented thinking
- Promotes early error detection through static structure
- Facilitates effort estimation through complexity analysis
- Must be documented and versioned
Core Components
- Class name
- Attributes with data type and visibility
- Methods with return type and parameters
- Inheritance
- Association
- Composition
- Aggregation
- Interface
- Dependency
- Multiplicity in relationships
Practical Example
// Example: Customers and Orders
class Customer {
-name: String
-email: String
+order(): void
}
class Order {
-date: Date
+calculateTotal(): float
}
Customer --> Order
Explanation: A customer can place orders. The arrow direction shows an association from customer to order.
Advantages and Disadvantages
Advantages
- High comprehensibility through standard notation
- Early visualization of software structure
- Support for object-oriented principles
- Helpful for team communication
Disadvantages
- No representation of temporal behavior
- Not suitable for dynamic processes
- Risk of over-complexity in large systems
Typical Exam Questions (with Short Answer)
- Class diagram represents? Structure of an object-oriented system with classes, attributes, methods, and relationships.
- Visibility levels in UML classes?
- public, - private, # protected
- Composition vs. aggregation? Composition means strict lifetime dependency, aggregation is a looser part-whole relationship.
- Interfaces represented? Interface with stereotype «interface» and dashed lines to implementing classes.
- Relationship types shown? Inheritance, association, aggregation, composition, dependency
- Advantages during development? Structured design and improved maintainability.
- Support testing? Clear delineation of responsibilities enables more targeted tests.
- Interface in class diagram? Collection of abstract methods that must be implemented by classes.