April 25, 2024

How to Draw UML Class Diagrams

Diagrams for Software Engineering
Back to top

What Are UML Class Diagrams? 

Class diagrams in Unified Modeling Language (UML) are a type of application architecture diagram used for conceptual object-based modeling or data modeling that describe the relationships and interactions between a system's components.

Class diagrams, like many other types of UML diagrams, help you simplify complex structures so you can easily communicate them to stakeholders throughout the business. They can also be helpful for project planning.

With this tutorial, we’ll make it easy for you to create UML class diagrams to describe any system, no matter how complex. Start your evaluation of Gliffy to follow along.

Try Gliffy Free

Back to top

Class Diagram Elements & Notation

Class diagrams can include a wide variety of symbols and elements depending on the complexity of the system — but the two essential elements of any class diagram are classes and interactions.

Classes

Classes, the central objects in a system, are the building blocks of UML class diagrams. They are shown in a diagram as rectangles with varying levels of detail depending on the object being visualized.

  • Upper Section: The top section of a UML class names the class and is always required. 
  • Middle Section: The middle section of a UML class describes the attributes of the class and may not be required for every class.
  • Bottom Section: The bottom section of a UML class lists its operations, which define its behavior and interactions. This may not also be required for every class.

Attributes within classes also have different access levels that define their visibility. They are represented by different symbols for public (+), private (-), protected (#), and package (~) elements.

Interactions 

There are many types of interactions that you can visualize with your class diagram, and each type is represented by a different type of line or arrow between classes. Two of the most common interactions in a UML class diagram are association and inheritance.

Associations

Associations are lines between classes that indicate some kind of connection between them. This could mean that both classes are aware of each other or only one is aware of the other — the arrowhead (or lack thereof) on either side of the line indicates the level of interaction.

Inheritance

Inheritance refers to a relationship between a parent class and a subclass that serves as an extension of it. This is represented by an arrow with an open head pointing toward the parent class from the subclass. 

Back to top

2 Ways to Create Class Diagrams

Method 1: Create Class Diagrams From Code

Want to create a class diagram to document your system, but short on time? When you diagram  in Confluence with Gliffy, you can generate class diagrams from code with Mermaid markdown, so you can enjoy the benefits of visual documentation without spending time you don’t have on making every shape and line look just right.

1. Open a new Gliffy diagram and click the lightbulb icon.

Type /gliffy onto any Confluence page to open the Gliffy editor, then click the lightbulb icon on the far left side of your screen.

Blank Gliffy diagram with the Mermaid panel open

 

2. Select “Mermaid” in the panel that opens. 

This will take you to the Mermaid editor, where you can construct your diagram.

Gliffy Mermaid editor with class diagram sample text

 

3. Enter your code, then click “Build Diagram.”

Inside the Mermaid editor, you can type (or copy and paste) the text that represents the way you want your diagram to look. When you’re done, click “Build diagram” and your automatically-generated diagram will be inserted onto the canvas.

Mermaid diagram on Gliffy canvas

 

It’s easy to edit your Mermaid diagram after creating it — just double click on it and you will re-enter the editing modal and can change the text as necessary.

Tip: For more help with Mermaid in Gliffy, check out our Mermaid diagramming tutorial >>

Method 2: Create Class Diagrams With Shape Libraries

If you aren’t familiar with Mermaid and would prefer to create your diagram by dragging and dropping shapes onto the canvas, good news: Gliffy makes it easy and intuitive to diagram that way as well.

Prefer to learn from a video? Check out our UML Class Diagram tutorial >>

1. Create a blank diagram or start from a template. 

Type /gliffy on any Confluence page to create a new diagram. In the panel that opens, select “Software Design: UML & ERD” to start from scratch or find a template by scrolling down and selecting the “Software Design & UML” category (pictured below).

Gliffy template library with Class Diagram template selected

 

2. Drag and drop classes onto the canvas.

If you don’t see the shapes you need, click “More Shapes” at the bottom left of your screen and make sure you have all the UML libraries selected. Once you have access to the proper libraries, you can find specific shapes faster by searching for them in the search bar at the top of the shapes panel.

UML classes on Gliffy canvas

 

3. Use connectors to bring it all together.

Gliffy offers the ability to use many different arrow styles to illustrate the relationships between your diagram classes. When you select a line, click the line icon to edit its properties.

Gliffy class diagram with line selected

 

Back to top

Draw UML Class Diagrams Directly in Confluence

Creating technical documentation for object-based programming is easier with Gliffy, because it allows you to visually document objects and their interactions directly in Confluence.

Whether you’re creating your class diagram with Mermaid markdown or by drawing your own diagram with our built-in UML shape libraries, it’s free to get started today.

TRY GLIFFY FOR CONFLUENCE

Back to top