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.

Class Diagram Example
Loading...
Inheritance Example

Composition

Composition represents a strong "has-a" relationship where the child cannot exist without the parent. Use *-- (filled diamond).

Class Diagram Example
Loading...
Composition Example

Aggregation

Aggregation represents a weaker "has-a" relationship where the child can exist independently. Use o-- (hollow diamond).

Class Diagram Example
Loading...
Aggregation Example

Association

Association represents a general relationship between classes. Use -- for bidirectional or --> / <-- for directional.

Class Diagram Example
Loading...
Association Example

Multiplicity

Specify how many instances participate in a relationship using multiplicity notation.

Class Diagram Example
Loading...
Multiplicity Example

Dependency

Dependency represents a "uses" relationship where one class depends on another but doesn't own it. Use ..> or <...

Class Diagram Example
Loading...
Dependency Example

Implementation (Interface Realization)

Implementation shows that a class implements an interface. Use <|.. or implements keyword.

Class Diagram Example
Loading...
Implementation Example

Relationship Labels

Add labels to relationships to describe their nature or purpose.

Class Diagram Example
Loading...
Relationship Labels Example

Relationship Types Summary

TypeSyntaxDescription
Inheritance<|--Is-a relationship, subclass inherits from superclass
Composition*--Strong has-a, child cannot exist without parent
Aggregationo--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