WORKED EXAMPLE · LESSON 6 · CLASS DIAGRAMS

Class Diagram: RPG Character

Pick a part from the list. It lights up in the diagram and in the C# code, and is explained below.

1. Explore the worked example

UML class diagram. Party has Characters. Character owns an Inventory, which owns Items. Weapon and Equipment inherit from Item.

Start here

Choose "A class" to begin. Each class is a box with three parts: name, attributes (data) and methods (actions).

The same diagram as C# code

Pick a class, then click any line of code to see which part of the diagram it comes from.

Build your own class diagram

Start with + Add class, or choose an example from the list and select Create example. Add classes, then give each one attributes, methods and links. The diagram and the C# update as you type. Ask yourself: is a Goblin a Monster? Then inherit (is-a). Does a Player have Health? Then link it with composition (has-a).

Add as many classes as you need within each diagram. Each named diagram saves separately on this device.

Checks

    Your C# code

    3. Review your own game (30 mins)

    Use the builder above to draw a class diagram for your own game, for example a Player with Movement and Health, or a Monster with variants.

    • Give your Character class 4 to 6 attributes with types and visibility.
    • Add 2 to 3 methods, for example Move(), Attack(), Die().
    • Link it to at least one other class (Inventory, Weapon, Party...) and label the multiplicity.
    • Write the C# for your class: fields, a constructor if you used composition, and method stubs.
    • Check: did you use inheritance, and composition or aggregation, in the right place?

    Download your work

    The illustrated report includes diagrams, C# code and reflection. SVG contains the diagrams; Markdown includes the diagrams as inline SVG along with code and reflection.


    4. Reflect

    What? So What? Now What? Three questions, one next step. Write one to three sentences for each.

    Based on Borton, T. (1970) Reach, Touch and Teach; developed by Rolfe, Freshwater and Jasper (2001).

    Example diagram

    Code example

    Learn more