UML For Hackers: Lean Class Diagrams
February 27th, 2008
UML is usually seen as a very corporate (i.e., boring) tool. It implies planning, best practices, and all those other things.
Hacking is usually described as a paradigm of just sitting down and starting to code, and altering your architecture along the way as you need to.
I think that’s fine, possibly even beneficial, for small projects, or projects worked on my one individual. But as soon as you decided to get a team working on a project… you need some way to represent parts of the application so people know how it works. Yes, we could just invent a new ad hoc representation scheme every time we need to do this… or we could just use UML.
UML has the advantage that some smart people put a lot of time into thinking about how it should work. Martin Fowler has a particularly good book on the subject, UML Distilled. This post might be thought of as UML Even More Drastically Distilled.
Class Diagrams
So, how about class diagrams, then. Here’s the bare minimum (IMHO):
Classes
- A Class is a rectangle.
- If you want to name it, name it at the top and put a line under it.
- If it has attributes you want to remember, list them under the name.
- If you want to add methods (class functions), draw a line under your attributes and list them there.
- If you think some methods are obvious, then just don’t list them; as long as everyone else will think they’re obvious, too: get_x() and set_x() might be obvious. put_fuzzy_bunny_at_x() might not be.
- You can use + or – in front of attributes or methods to indicate public or private respectively. (# for protected, if you want that).
Relationships
- Subclassing (is-a) is represented by small open triangle under the superclass, and a line or lines to the subclass(es).
- Aggregation (has-a) is represented by a small open diamond from “having” class, and a line to the attribute class. If another class is an attribute like this, you wouldn’t need to list it in the attributes necessarily; the class diagram makes it clear that Car has an Engine (for example).
There’s more, but do you really want to know it? We want a lean toolkit, here. Ok, fine; you can look at the quick reference card or this handy cheatsheet.

Sorry, comments are closed for this article.