UML - Class Diagram Tutorial
Class diagrams may seem confusing, but with the right resources, you can make them all on your own. Follow these detailed instructions to learn how.
Create a variety of UML diagrams, including class diagrams, with Lucidchart. Our simple online editor makes it easy to map any process or workflow right from your browser!Try it now Sign up free
How to Create Class Diagrams
To start this UML class diagram tutorial, let's review the basics. Be sure to understand what a class diagram is. It might also be a good idea to read this page on what is UML, so you have a firm grasp of the underlying language of class diagrams. When you have the right tools on hand—including a diagramming program like Lucidchart—you can move to the next step.
LIST RELEVANT ELEMENTS
Class diagrams seem overwhelming because there are so many model elements that could be included. The good news is that your class diagram can be as simple or complicated as you wish. Before you proceed, take a look at the application you want to model. Write down the name, attributes, and methods that correspond to each class, then note the relationships that exist between classes. Remember that class diagrams can help you:
- Demonstrate responsibilities of a system
- Analyze and design a static view of an application
- Build additional charts, like component and deployment diagrams
- Construct the executable code for forward- and reverse-engineering of a system
ADD SHAPES AND SYMBOLS
Begin your class diagram with the UML class shape. It features three rows, but you can choose a shape without the bottom two rows. In Lucidchart, all symbols can be dragged from the toolbox to the canvas.
Click to type information into each row of the class shape. The first row should feature only the class name. The middle section contains the attributes of the class. The bottom row shows possible methods or operations the class may take. The text of these last two rows is typically left-aligned with a lowercase first letter.
Continue to add class shapes until your static application is fully represented. When that's finished, it's time to tackle three important concepts: scope, visibility, and interaction.
Scope applies to all members (i.e. attributes or methods) of a class. They can fall into one of two classifications: instance or classifier. Classifier members are usually recognized as static. Attribute values remain the same in all instances, and method invocation doesn't affect the instance's state. In contrast, instance members have attribute values that may vary between instances, and methods can alter the instance's state. Indicate a classifier by underlining its name (a non-underlined member is assumed to be an instance).
Visibility, also known as access, of a class member is indicated with a symbol placed within the class shape and before the specific attribute or method. (visiblity). This list shows access levels with their corresponding symbols:
- Public (+)
- Private (-)
- Protected (#)
- Package (~)
- Derived (/)
Interactions are the relationships and links that can exist in class and object diagrams. There are too many interaction types to list here, but some of the most common ones can be seen on this class diagram definition page. In Lucidchart, you can indicate relationships between objects by drawing a line, then changing the notation style as needed.
REVIEW YOUR WORK
Now that you've built your class diagram, take the finished product to your teammates. They'll be able to provide a unique perspective that will simplify and improve the diagram.
With Lucidchart, it's easy to create great-looking diagrams for school or work. From any device or operating system, you can make class diagrams, use case diagrams, activity diagrams, and much more.