UML Class Diagram Explanation
This section explains the key concepts of Class Diagrams and UML as described below.
Class Diagram Symbols
The main symbols shown on class diagrams are:
- Classes: Represent the types of data themselves.
- Associations: Represent linkages between instances of classes.
- Attributes: Simple data found in classes and their instances.
- Operations: Functions performed by the classes and their instances.
- Generalizations: Group classes into inheritance hierarchies.
Diagram: Class Diagram Symbols
Refer to the PDF for the visual representation of class diagram symbols.
Classes
A class represents a concept and encapsulates state (attributes) and behavior (operations). Each attribute has a type, and each operation has a signature. The class name is the only mandatory information.
Diagram: Class Example
Refer to the PDF for the visual representation of a class with attributes and operations.
Associations and Multiplicity
Associations show how two classes are related to each other. Multiplicity symbols indicate how many instances of one class are related to another. For example:
- One-to-One: A company has exactly one board of directors.
- Many-to-One: A company has many employees, but an employee works for only one company.
- Many-to-Many: An assistant can work for many managers, and a manager can have many assistants.
Diagram: Association Example
Refer to the PDF for the visual representation of associations and multiplicity.
Aggregation and Composition
Aggregation is a special type of association that models a whole-part relationship. For example, a college is made up of students, but students can exist independently of the college.
Composition is a stronger form of aggregation where the parts cannot exist without the whole. For example, a house is composed of rooms, and if the house is destroyed, the rooms are also destroyed.
Diagram: Aggregation and Composition
Refer to the PDF for the visual representation of aggregation and composition.
Generalization and Inheritance
Generalization is used to create inheritance hierarchies. Subclasses inherit attributes and operations from their superclass. For example, a Button
class can have subclasses like ZoneButton
and CancelButton
.
Diagram: Generalization and Inheritance
Refer to the PDF for the visual representation of generalization and inheritance.
Example: Company Structure
A company consists of departments, which are located in one or more offices. Each department has a manager recruited from the set of employees. This can be modeled using a class diagram with classes like Company
, Department
, Office
, and Employee
.
Diagram: Company Structure
Refer to the PDF for the visual representation of the company structure class diagram.