A short introduction to PlantUML

Introduction

Unified Modeling Language (UML) is presented in academia mainly through GUI applications which implement the aforementioned standard, all of which are inefficient to navigate and hard to maintain. PlantUML is a tool that implements UML in a unique manner - a textual language - leading to significant improvements in many areas:

My computing environment is revolved around the philosophy of a keyboard-centric worfklow. I find that it saves me a lot of time and energy not having to move my hands beyond the home row, and it's gratifying to jump back and forth between my windows and workspaces at the speed of light. PlantUML, being text-driven, does not hamper my workflow, rather it extends it.

Showcase

Let's represent the animal kingdom in a class diagram, abstracting it the objected oriented way. Give this a good read.

package Animalia {

  Animal <|-- Feline
  Animal <|-- Canine

  Feline --> Felidae
  Canine --> Canidae

  abstract class Animal {
     {abstract} void jump(height: int)
     {abstract} void run(velocity: int)
  }

  class Feline {
     - species: Enum<Felidae>
     + jump(height: int)
     + run(velocity: int)
  }

  class Canine {
     - species: Enum<Canidae>
     + jump(height: int)
     + run(velocity: int)
  }

  enum Felidae {
     Jaguar,
     Lion,
     Cougar
  }

  enum Canidae {
     Wolf,
     Fox,
     Dog
  }
}

Inside the Animalia package, we find two classes, Feline and Canine which implement the functions defined in Animal, our abstract class. We've also got two enums, Felidae, and Canidae, which hold as many species of the two families as I can possibly think of.

Okay, so how do we tie everything together? You guessed it, with arrows!

We can represent aggregation between two classes with <|-- or --|>, and to represent a normal relationship between two things, such as what you see between the different enums and classes, we can use <-- or -->.

The direction of the pointy bit matters, and it will be reflected as is in the output diagram.

The last thing I'll cover is access modifiers, all of which are assigned a unique icon by PlantUML. Prepending a method or attribute with a + will indicate that it's public- is private – # is protected and ~ is package private. It's sort of your responsibility to use them appropriately, as PlantUML won't stop you from shooting yourself in the foot.

To see the result of the diagram's textual representation, place the contents of the source in a file, e.g. animalia.puml and run the following command in a shell:

plantuml animalia.puml -tpng animalia.png

You should then see an animalia.png file appear in your working directory… Go on, open it, it should look like this:

PlantUML class diagram depicting inheritance

I hope I've given PlantUML the proper introduction it deserves. We have barely even touched the surface of what PlantUML can do, but we're already capable of doing so much.