Introduction

UML (Unified Modeling Language) is a graphical language for modeling the structure and behavior of object-oriented systems. UML is widely used in industry to design, develop and document complex software. This page will focus on creating UML class diagrams, which describe the internal structure of classes and relationships between classes.

For additional information beyond the usual suspects (your textbook and Wikipedia), see UML Basics: The Class Diagram.

Classes

A class diagram contains a rectangle for each class. It is divided into three parts.

  1. The name of the class.
  2. The names and types of the fields.
  3. The names, return types, and parameters of the methods.

For example, a Person class and a Book class might be modeled like this.

This indicates that a Person object has private fields named name and birthDate, and that it has public methods named getName, setName and isBirthday. A Book object has private fields named title and authors. A Book object also has public methods named getTitle, getAuthors and addAuthor.

The examples below also model a Person class and Book class, but only shows fields or methods as needed for illustration.

Use Relationships

Often, objects and/or methods of one class use objects/methods from another class. For example, a person might read and/or own a book, and these relationships might be modeled in the UML diagram, so that they will be implemented in the corresponding program.

UML class diagrams include the following types of use-relationships, in order from weakest to strongest.

If you have difficulty distinguishing among association, aggregation and composition relationships, don't worry! So does everybody else!

Inheritance Relationships

The inheritance relationships in UML match up very closely with inheritance in Java.