Whimsical LogoWhimsical LogoWhimsical Logo

Brand
Get all logo versions.
Download

Class Diagram

A class diagram is UML's structural blueprint: the classes in a system, their attributes and methods, and how they relate, from inheritance to composition. This template is the class diagram of a Python task runner: six classes with typed attributes, dataclass and enumeration stereotypes, visibility markers, and a self-association. Developers use it to design before coding and to document the code that exists.

A worked UML class diagram of a task runner, from attributes to relationships.

What's included

  • A complete worked system. Six classes from a Python task runner: Runner, Workflow, Task, a status enumeration, and two helpers.
  • Full UML notation in use. Three-compartment boxes, + and - visibility, typed attributes with defaults, and method signatures with return types.
  • Stereotypes that match the code. «dataclass» on the value objects and «enumeration» on the status type, mapping notation to real Python constructs.
  • Every relationship kind. Aggregation with multiplicities (tasks 0..*), dashed «use» and «create» dependencies, and a depends_on self-association.
  • A status enum wired in. TaskStatus (pending, success, failed, skipped, retrying) linked from Task with multiplicity 1.

Why draw a class diagram?

  • Design before the code hardens. Moving a method between classes on a diagram costs nothing; after three sprints it's a refactor ticket.
  • The structure becomes arguable. Whether Task should own its retry logic is a better conversation pointed at a diagram than at 400 lines.
  • Self-associations expose the hard parts. The depends_on 0..* loop on Task is one arrow here and a week of cycle-detection bugs if nobody saw it coming.
  • Onboarding reads one picture. A new engineer learns the object model in five minutes instead of spelunking through imports.
  • It bridges code and conversation. Stereotypes like «dataclass» keep the diagram honest to the implementation instead of an idealized sketch.

How to use this template

  1. List the classes. One box per class your system actually has or needs; name them as the code names them.
  2. Fill the compartments. Attributes with types and defaults in the middle, methods with signatures below; mark + public and - private.
  3. Add stereotypes. «dataclass», «enumeration», «interface»: the guillemet labels that tell readers what kind of class they're looking at.
  4. Draw the relationships. Solid lines for associations with multiplicities at the ends, diamonds for has-a, dashed arrows for «use» and «create».
  5. Check for self-references. If a class points at itself, like a task depending on tasks, draw the loop; that's where the interesting bugs live.
  6. Keep it honest. Update the diagram when the code changes, or reverse-engineer a fresh one before big refactors.

Class diagram vs ER diagram

Both draw boxes with attributes and connect them, which is where the resemblance ends. The class diagram is about objects in code: methods, visibility, inheritance, composition, dependencies, the living behavior of a system. The ER diagram is about data at rest: entities, keys, and cardinality, destined for tables. Design the software with a class diagram; design its database with an ER diagram. Most products need both, and the entities will overlap without matching one to one.

Frequently asked questions

  • A class diagram is the UML diagram that shows a system's static structure: its classes, each with attributes and methods, and the relationships between them, inheritance, association, aggregation, composition, and dependency. It's the most used UML diagram, drawn at three levels of detail: conceptual for domain modeling, design for architecture, and implementation for diagrams that map one-to-one onto code, like this template's.

  • Each class is a box with three compartments: name, attributes, methods. A + prefix means public, - private, # protected. Lines carry the relationships: a solid line is an association (with multiplicities like 1 or 0..* at the ends), a hollow diamond is aggregation, a filled diamond is composition, a hollow triangle arrow is inheritance, and a dashed arrow is a dependency, often labelled «use» or «create».

  • This template's board is one: a task runner where a Runner «uses» a Workflow, the Workflow aggregates Tasks (0..*), each Task carries typed attributes like func: Callable and retry settings, holds a status from a TaskStatus «enumeration», and depends on other Tasks through a 0..* self-association. Tracing one feature through the diagram, say, how a failed task marks its dependents as skipped, is a good test that the structure holds.

  • A class diagram models objects with behavior: classes carry methods, visibility, and dependencies, and the relationships include inheritance and composition. An ER diagram models stored data only: entities, attributes, keys, and cardinality, with no methods anywhere. They often describe the same domain; the Task class here would flatten into a tasks table in the database's ER diagram, losing its methods on the way.

  • Three moments pay best. Before building: a design-level diagram settles where responsibilities live while moving them is free. Before refactoring: reverse-engineering the current structure exposes the tangles you're about to touch. And when onboarding: the diagram is the map a new engineer reads first. Skip the conceptual-everything diagram of the whole codebase; one diagram per subsystem, at the detail level the audience needs.