Skip to main content

Introduction to UML — Why Visual Modeling Matters

Editorial

Introduction

Before a house is built, the architect hands over a set of drawings: a floor plan, the front of the house, the wiring, the plumbing. Each drawing shows the same house from a different side, and each answers questions the others cannot. Nobody would pour concrete without them.

Software has the same need. A design lives in many files of code, and the code is the only place where every detail is right, but it is a hard place to see the shape of a system from. UML, the Unified Modeling Language, is a standard set of drawings for software: it gives the structure of a system and the way it behaves a shared notation that anyone who knows UML can read.

This part of the course teaches five UML diagrams, all on one example, a library's lending system, so you can see one system through five different drawings.

What Is UML?

The specification that defines UML states its aim plainly: "The objective of UML is to provide system architects, software engineers, and software developers with tools for analysis, design, and implementation of software-based systems as well as for modeling business and similar processes." It is published by the Object Management Group (OMG); the version this course quotes is UML 2.5.1.

UML did not start from nothing. Before it, several design methods each had their own way of drawing classes and their relationships, and "The initial versions of UML (UML 1) originated with three leading object-oriented methods (Booch, OMT, and OOSE)". Merging them gave designers one notation instead of several.

UML is a notation: it defines what each diagram means and leaves it to you when to draw one, how much detail to put in, and whether to keep it. It defines more kinds of diagrams than most designers ever use; this course teaches the five that low-level design leans on.

Why Draw at All?

Imagine joining a team that runs a large online shop, and your first task is to add a new way to pay. Before you change anything, you need to know which classes handle payments, how a payment moves through the system, which states an order can be in, and who starts a payment. All of it is in the code, spread across many files. A class diagram, a sequence diagram, a state machine and a use case diagram can each show one of those answers on a single page.

That is what diagrams are good for. A team can point at the same drawing while it talks about a design, and agree or disagree with something concrete. A diagram leaves out what does not matter for the question at hand, such as the private helper methods inside a class, and shows how the parts connect. And drawing relationships before writing code makes you decide them early: whether a part outlives its whole, who keeps a reference to whom. Those decisions are cheap to change on a whiteboard and expensive to change once code depends on them.

A diagram is still a document, and documents go stale. A class diagram drawn last year does not change when the code changes, so the code stays the final word. Keep the diagrams you still use, redraw them when the design moves, and throw the rest away.

Two Kinds of Diagrams

UML sorts its diagrams into two kinds: "there are two major kinds of diagram types: structure diagrams and behavior diagrams."

"Structure diagrams show the static structure of the objects in a system." They answer what exists and how it is related, whatever happens over time. The structure diagram this course teaches is the class diagram: classes, their fields and methods, and the relationships from Association — Objects That Know Each Other to Generalization vs Specialization. It is the floor plan of the system.

"Behavior diagrams show the dynamic behavior of the objects in a system": what happens, in what order, and how things change. This course teaches four of them:

  • The use case diagram shows the people and outside systems that use the system, and what each of them can do with it.
  • The sequence diagram shows the messages objects send each other for one scenario, in the order they are sent.
  • The activity diagram shows a workflow: steps, decisions and the paths between them.
  • The state machine diagram shows the states one object can be in and the events that move it from one to another.

The line between the two kinds is not rigid, and the specification says so: "the boundaries between the various kinds of diagram types are not strictly enforced."

The Five Diagrams at a Glance

Each diagram answers a different question about the same system:

DiagramQuestion it answersIn the library
Class diagramWhat exists, and how is it related?Book, Member, Loan and Librarian, and how they connect
Use case diagramWho uses the system, and for what?A member borrows a book; a librarian adds one
Sequence diagramHow do objects interact in one scenario?The calls, in order, when a member borrows a book
Activity diagramWhat is the workflow, with its decisions?Borrowing: check the book, then lend it or turn the member away
State machine diagramWhat states can an object be in?A book: available, borrowed, reserved or lost

The picture shows all five, each on a small piece of the library:

One system, five diagrams: the Library Management System seen through five UML diagrams. Structure, what the system is made of: a class diagram of Member (name), Loan (dueDate) and Book (title, isbn, status), a member with any number of loans and each loan of one book, answering what exists and how it is related. Behavior, what happens in it over time: a use case diagram, a member with two use cases inside the library, borrow a book and return a book, answering who does what; a sequence diagram, the lifelines of a member, the library and a book, with the messages borrow and check and the answers free and loan coming back, dashed, answering how objects interact over time; an activity diagram, from the start the book is checked, and if it is free a loan is issued, if it is out the member is turned away, answering what the workflow is; a state machine diagram of a book, Available, then Borrowed by borrow, back to Available by return, or Lost, answering what states an object can be in.

The Running Example: A Library

Every diagram in this part is drawn for one system, a library's lending system, so that you can compare the drawings directly.

What the system does:

  • Members can search the catalog, borrow books, return books, and reserve books that are currently checked out.
  • Librarians can add new books, register new members, and manage overdue fines.
  • The system tracks which books are available, borrowed, or reserved.
  • Overdue books incur daily fines that members must pay before borrowing again.

What it is made of:

  • Book: a title, an author, an ISBN, and a status (Available, Borrowed, Reserved or Lost).
  • Member: a name, a membership card and a borrowing history.
  • Librarian: a member who can also manage the books and the members.
  • Loan: one borrowing, with the book, the member, the borrow date and the due date.
  • Reservation: a hold a member places on a book.
  • Fine: what a member owes for a late return.

By the end of this part you will have drawn its structure as a class diagram, its users and their goals as a use case diagram, the messages of a borrow as a sequence diagram, a workflow such as borrowing, which checks the book and either issues a loan or turns the member away, as an activity diagram, and a book's life as a state machine. The ideas under them are the ones you already know: classes and objects from Classes and Objects — Blueprint vs Instance, and the relationships from Association — Objects That Know Each Other onwards.

UML in LLD Interviews

Interview advice on UML is not unanimous, and it is worth knowing both sides.

One guide to these interviews leaves strict UML out on purpose: "You won't see UML as part of our breakdowns." It asks for a plainer outline of the classes instead: "You're not drawing a full UML diagram, you're just communicating structure that you can build on later." Its view of UML is blunt: "It's outdated and very rarely used in production systems." It also notes that some interviewers do ask for UML, and advises asking whether a simplified class notation will do.

Whichever notation you use, the ideas are the same: which classes exist, what each holds, which ones keep a reference to which, which ones only use another, and which ones are kinds of another. UML is the standard vocabulary for those ideas, and every class figure in this course is drawn in it. Knowing it lets you read other people's designs, and lets you draw your own in full UML or as simple boxes and arrows, whichever the person across the table prefers.

If you do draw during an interview, each diagram suits a moment of the conversation: a use case sketch when you confirm who uses the system and for what, a class diagram when you lay out the design, a sequence diagram when you walk through one scenario, an activity diagram for a decision-heavy workflow, and a state machine for an object whose states drive the rules, such as an order that is placed, shipped and delivered.

Common Misconceptions

Misconception 1: "UML is dead, nobody uses it." Drawing every kind of diagram before writing any code has gone out of fashion, and some interview guides skip UML altogether. But its notation for classes and their relationships is what you will meet in many books and design documents, and in every class figure of this course. Knowing it costs little and lets you read all of them.

Misconception 2: "UML means a slow, plan-everything process." UML says how to draw a design and nothing about how to plan the work. A team that plans in short steps can sketch a class diagram on a whiteboard for ten minutes and throw it away afterwards.

Misconception 3: "I have to memorize every symbol." Each page in this part teaches the notation for its own diagram, and only the symbols that diagram needs. You will not need the rest of the specification for design work or interviews.

Misconception 4: "A diagram has to be complete and exact." A diagram is a sketch of the decisions that matter. Put in the key classes and relationships, and leave out getters, setters and other details nobody will argue about. The drawing exists to communicate a design, and the code fills in everything else.

What Comes Next

The next six pages take the diagrams one at a time, all on the library:

A checkpoint closes the part. If the relationships still feel shaky, Association — Objects That Know Each Other and the pages after it are worth a second look first, since a class diagram is those ideas drawn.