Relationships
Relationships define how classes interact and relate to each other. Understanding different relationship types is crucial for accurate system modeling.
Inheritance (Generalization)
Inheritance represents an "is-a" relationship where a subclass inherits from a superclass. Use <|-- or extends keyword.
Composition
Composition represents a strong "has-a" relationship where the child cannot exist without the parent. Use *-- (filled diamond).
Aggregation
Aggregation represents a weaker "has-a" relationship where the child can exist independently. Use o-- (hollow diamond).
Association
Association represents a general relationship between classes. Use -- for bidirectional or --> / <-- for directional.
Multiplicity
Specify how many instances participate in a relationship using multiplicity notation.
Dependency
Dependency represents a "uses" relationship where one class depends on another but doesn't own it. Use ..> or <...
Implementation (Interface Realization)
Implementation shows that a class implements an interface. Use <|.. or implements keyword.
Relationship Labels
Add labels to relationships to describe their nature or purpose.
Relationship Types Summary
| Type | Syntax | Description |
|---|---|---|
| Inheritance | <|-- | Is-a relationship, subclass inherits from superclass |
| Composition | *-- | Strong has-a, child cannot exist without parent |
| Aggregation | o-- | Weak has-a, child can exist independently |
| Association | -- or --> | General relationship between classes |
| Dependency | ..> or <.. | Uses relationship, one class depends on another |
| Implementation | <|.. | Class implements an interface |