3.1 & 3.4 Class Diagrams & UML Class Relationships
Class Diagram: The central static structural diagram in UML showing system classes, attributes, operations, and relationships.
Class Notation: A 3-compartment rectangle: Top (Class Name), Middle (Attributes: visibility name: type = default), Bottom (Operations: visibility name(parameters): return_type).
Visibility Modifiers: + Public, - Private, # Protected, ~ Package.
Fundamental Class Relationships:
- Association (Solid Line): Structural connection between classes with multiplicity (e.g.,
1..*). - Aggregation (Hollow Diamond on Parent): Weak 'has-a' whole-part relationship where parts can exist independently of the whole (e.g., Department $\diamondsuit$β Professor).
- Composition (Filled Black Diamond on Parent): Strong 'has-a' whole-part relationship where parts cannot exist without the whole (e.g., House $\blacklozenge$β Room). Lifetimes are tightly bound.
- Generalization / Inheritance (Solid Line with Hollow Triangle): Subclass inherits from superclass.
- Dependency (Dashed Arrow $\dashrightarrow$): 'Uses-a' relationship; changes in supplier affect client.
- Realization (Dashed Line with Hollow Triangle): Class implements an interface contract.