UML Class Diagrams Explained for Beginners

UML class diagram with three-part class boxes connected by association, inheritance and diamond relationship lines

UML class diagrams are simple drawings that map out a program's structure: its classes, the data each class holds, what each class can do, and how the classes connect. They use only boxes, lines and a few small symbols. Once you know those symbols, you can read almost any design sketch a team puts in front of you.

This guide covers each piece in order: the three-part class box, the visibility symbols, the four main kinds of lines, and the small numbers that say how many objects are involved. It then puts everything together in a library example and ends with the three mistakes beginners make most often.

In short
  • A UML class diagram shows classes, their attributes (data), their operations (behavior) and their relationships.
  • Each class is a three-part box: name on top, attributes in the middle, operations at the bottom.
  • Plus means public, minus means private, hash means protected and tilde means package.
  • Association, inheritance, aggregation and composition lines each describe a different kind of link.
  • Multiplicity numbers at both ends of a line turn a vague connection into a clear rule.
  1. 0:00Intro
  2. 0:26Everyone pictures the code differently
  3. 1:15A map of your program's classes
  4. 2:14Draw each class as a three-part box
  5. 3:16Mark visibility with plus and minus
  6. 4:14Association and inheritance lines
  7. 5:02Aggregation versus composition
  8. 5:51Add multiplicity to every line
  9. 6:44Modeling a library system
  10. 7:35Where teams actually use them
  11. 8:23Three mistakes beginners make
  12. 9:17Everything in one glance
  13. 9:52Simple diagrams lead to clearer thinking

What is a UML class diagram, and why draw one?

Imagine a team starting work on a new shop app. Everyone agrees on the idea, but each person pictures a different structure in their head. Talking about a design is easy. Agreeing on one is much harder. Questions like "which class owns the orders?" tend to surface late, often as rewrites after the first code review, when the mismatch finally shows.

The problem is that spoken plans drift. When a design lives only in conversation, each person quietly fills the gaps with their own assumptions, and nobody notices until the code disagrees. A shared drawing fixes this. People can point at a box and ask a question about it, so problems get caught on paper, where they are cheap to fix.

A UML class diagram is that shared drawing. UML is a standard visual language, so the same symbols mean the same thing to every developer who knows it. Think of the diagram as a map of your program. In a tiny online shop, a Customer places an Order, the Order contains a Product, and a Payment pays for it. Four classes and three lines already explain how the system fits together.

  • Data: what each class knows, such as a product's name and price (called attributes)
  • Behavior: what each class can do, such as cancelling an order (called operations)
  • Relationships: the lines that show who uses whom and who owns what

How to draw a class box

Every class is drawn as a rectangle split into three stacked sections. The order never changes: the name goes on top, the data goes in the middle, and the actions go at the bottom. A Customer class, for example, has the name Customer at the top, attributes such as name and email in the middle, and an operation such as placeOrder at the bottom.

Use a singular noun for the name, written in bold: Customer rather than Customers. The box describes one kind of thing, not a collection. Write attributes as name, colon, type, such as email : String, so readers know what kind of data each one holds. Write operations with parentheses, such as placeOrder(), so they are clearly actions rather than data.

With just these three parts, anyone can see at a glance what a class is, what it knows and what it does.

  • Top: the class name, a singular noun
  • Middle: attributes, written as name : type
  • Bottom: operations, written with parentheses

What do plus and minus mean in a class diagram?

A single symbol at the start of each attribute or operation shows its visibility, meaning who is allowed to see or use it. It is only one character per line, but it carries a lot of design meaning. In the Customer example below, name and email start with a minus, so they are private. placeOrder and getEmail start with a plus, so other classes can call them.

Plus means public: any other class can use it. Operations like placeOrder are usually public because they are how the rest of the program talks to a customer. Minus means private: only the class itself can touch it. Keeping data like the email private stops other code from changing it in unexpected ways.

Two more symbols exist. A hash (#) means protected, so the class and its subclasses can use it. A tilde (~) means package visibility. Beginners will see plus and minus far more often, but it helps to recognise the other two when they appear.

  • + public: any class can use it
  • - private: only the class itself
  • # protected: the class and its subclasses
  • ~ package: classes in the same package
# Customer class, UML style
- name : String
- email : String
+ placeOrder() : Order
+ getEmail() : String

Association vs inheritance: the two most common lines

Once each box is complete, lines connect them. There are four main kinds of line, and every one answers the same question: how are these two classes related? The two you will see most often are association and inheritance, and they describe very different links.

Association is a plain solid line. It means two classes know about each other and work together, such as a Customer placing an Order. You can label the line with a verb, like "places", so the relationship reads like a sentence.

Inheritance uses a line with a hollow triangle arrowhead pointing at the parent class. Read it as "is a". For example, a Customer is a kind of User, and an Admin is also a kind of User, so both arrows point to User. The benefit is that shared data lives once in the parent instead of being copied into every class that needs it.

Aggregation vs composition: what the diamond means

This is where beginners most often trip up. Aggregation and composition both mean that one class is made up of others, and both are drawn with a diamond at the "whole" end of the line. The difference lies in ownership and in what happens to the parts when the whole disappears.

Aggregation uses a hollow diamond. The whole uses its parts but does not own them, so the parts can survive on their own. A team and its players is a good example: a player can leave and join another team. Composition uses a filled diamond. The whole owns its parts, and they cannot exist without it. A house and its rooms is the classic case.

A useful memory trick: a filled diamond means fully owned. When you are unsure, ask whether the part can live alone. If yes, use the hollow diamond; if no, use the filled one. This matters in practice because the diamond tells developers which object is responsible for deleting what.

  • Aggregation: hollow diamond, whole uses the parts, parts survive alone
  • Composition: filled diamond, whole owns the parts, parts die with the whole

What is multiplicity in a UML class diagram?

A line on its own only says that two classes are linked. It does not say how many objects of each are involved. Multiplicity fills that gap with small numbers written at each end of the line.

Take the line Customer 1 — 0..* Order. Read the left end first: 1, so each order belongs to exactly one customer. Then read the right end: 0..*, meaning zero or more orders per customer. To test the rule, imagine a customer called Ana with three orders. Three fits within zero or more, so the design allows it.

These numbers decide real things, such as whether an order can exist without a customer. They shape database tables and validation rules, which is why multiplicity turns a vague line into a clear rule.

  • 1: exactly one
  • 0..1: optional (zero or one)
  • *: many
  • 1..*: at least one

Worked example: a library system class diagram

Here is everything combined in a small library system. In plain language: members borrow books through loans, and a library holds the books. A Member is a kind of Person, so that link is inheritance. Each Member has zero or more Loan records, and each Loan points to exactly one Book. The Library holds its books with a hollow diamond, because a book could move to another library.

The Loan class is the clever part. A loan is not a physical object; it is an event with a due date. Modelling it as a class gives that date a proper home. This shows that a class can stand for an event, not just a thing.

The biggest win is the questions the diagram raises. Can one member borrow the same book twice? Can a book have no library? A diagram surfaces questions like these before any code exists, when answering them is still easy.

Where teams actually use class diagrams

Class diagrams show up at several points in a project, not only at the very start. Teams use them for object-oriented design, to plan code before writing it. They use them as documentation, recording how things fit together. They serve as a database model, since classes often map to tables. And they help with onboarding, giving new developers the big picture in minutes.

Designing first is the biggest payoff. Moving a box on a whiteboard takes seconds, while restructuring classes in a finished codebase can take days of careful work. The second benefit is a shared language: because UML is a standard, a diagram drawn by one team reads the same way to another.

Three common class diagram mistakes and how to fix them

Most unhelpful class diagrams fail in the same three predictable ways, and each has a simple fix. The first is cramming in every detail. Adding every getter and helper method buries the main idea; forty boxes means zero clarity. Draw several small diagrams instead, each focused on one part of the system.

The second mistake is mixing up the diamonds, which makes the diagram quietly say the wrong thing about ownership. Before drawing one, ask whether the part can live without the whole: yes means a hollow diamond for aggregation, no means a filled diamond for composition.

The third is skipping multiplicity. A bare line hides the rules of the system and leaves readers guessing. Putting a number at both ends of every line takes seconds and prevents a lot of wrong assumptions.

  • Cramming every detail: show only the classes this diagram is about
  • Mixing up diamonds: ask whether the part can live alone
  • Skipping multiplicity: label both ends of every line

Key takeaways

  • A class diagram shows each class's data, behavior and links to other classes.
  • Each box holds a name, attributes and operations, in that order.
  • Plus is public and minus is private; hash and tilde cover protected and package.
  • Use association, inheritance and the two diamonds to describe how classes relate.
  • Label every line with multiplicity at both ends.
  • Keep each diagram simple and focused: draw less, say more.

Frequently asked questions

What are the three sections of a UML class box?

The top section holds the class name, written as a singular noun. The middle holds attributes, written as name : type. The bottom holds operations, written with parentheses, such as placeOrder().

What is the difference between aggregation and composition in UML?

Both mean one class is made of parts. Aggregation uses a hollow diamond and its parts can exist alone, like players on a team. Composition uses a filled diamond and its parts cannot exist without the whole, like rooms in a house.

What does 0..* mean in a class diagram?

It is a multiplicity value meaning zero or more. On a Customer–Order line, 0..* at the Order end means a customer can have no orders or many orders.

How do you show inheritance in a UML class diagram?

Draw a line with a hollow triangle arrowhead pointing at the parent class. Read it as "is a", for example a Customer is a User.

Should a class diagram include every class and method?

Usually not. Cramming in every getter and helper hides the main idea. Several small diagrams, each focused on one part of the system, are easier to read and more useful.

Watch the full video on YouTube →

Souy Soeng

Souy Soeng

Hi there 👋, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
👯 I’m looking to collaborate on open-source PHP & JavaScript projects
💬 Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
Ad