Game character class diagram
Warrior and mage inherit from character; a character composes an inventory that aggregates items. Four relationships in a topic students like.
The diagram
Reading it step by step
- 'Character' (abstract class): 1 attributes, 1 methods.
- 'Warrior' (class): 0 attributes, 1 methods.
- 'Mage' (class): 1 attributes, 1 methods.
- 'Inventory' (class): 1 attributes, 0 methods.
- 'Item' (class): 1 attributes, 0 methods.
- 'Warrior' inherits from 'Character'.
- 'Mage' inherits from 'Character'.
- 'Character' is composed of 'Inventory'.
- 'Inventory' aggregates 'Item'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Character | abstract | holds #hp int, +attack() int · → Inventory · ← Warrior, Mage |
| Warrior | Class | holds +defend() void · → Character |
| Mage | Class | holds +mana int, +cast() int · → Character |
| Inventory | Class | holds +slots int · → Item · ← Character |
| Item | Class | holds +name String · ← Inventory |
Symbols used here
| Symbol | Meaning |
|---|---|
| Class | A box with name, attributes and methods. |
| Inheritance | Solid line from child to parent, hollow triangle at the parent. |
| Composition | Filled diamond at the whole; parts die with it. |
| Aggregation | Hollow diamond at the whole; parts can live alone. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Game character class diagram
classDiagram
class Character {
<<abstract>>
#hp int
+attack() int
}
class Warrior {
+defend() void
}
class Mage {
+mana int
+cast() int
}
class Inventory {
+slots int
}
class Item {
+name String
}
Character <|-- Warrior
Character <|-- Mage
Character *-- Inventory
Inventory o-- Item