Diagram Desk

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

Character«abstract»#hp int+attack() intWarrior+defend() voidMage+mana int+cast() intInventory+slots intItem+name String
Class diagram · 12 shapes

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

ShapeSymbolConnections
Characterabstractholds #hp int, +attack() int · → Inventory · ← Warrior, Mage
WarriorClassholds +defend() void · → Character
MageClassholds +mana int, +cast() int · → Character
InventoryClassholds +slots int · → Item · ← Character
ItemClassholds +name String · ← Inventory

Symbols used here

SymbolMeaning
ClassA box with name, attributes and methods.
InheritanceSolid line from child to parent, hollow triangle at the parent.
CompositionFilled diamond at the whole; parts die with it.
AggregationHollow diamond at the whole; parts can live alone.

All class diagram symbols and how to draw

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

More class diagram examples

All SeewolLabs tools