...
Line
Skip to main content
< All Topics
Print

How to make a UML class diagram

What is a UML diagram?
For starters, UML means Unified Modeling Language and it’s a standardized visual language used most often in, but not exclusively, software development, IT and business systems.

The idea is to have a uniform way to represent the classes, objects, relationships and interactions within simple or complex systems
to make it easier for developers and stakeholders to understand and communicate about the system.

Here’s how to make a UML diagram
Because there are so many types of UML diagrams, we’re going to focus on just one and make this specifically a UML class diagram tutorial because it’s among the most commonly used.

A quick definition: UML class diagrams are used to show and define a system’s static classes, attributes, methods and relationships between classes.

Step1: Define the purpose and scope
The first step of how to make a class diagram is simple, identify and describe the system you’re modeling. This can be anything but to keep things straightforward and make the relationships that we document easier to understand, we’ll use the NFL as an example.

Step2: Identify and label classes
Classes are the main objects or major components of a system; the highest level.

Using our simple NFL team example, we can break things down into 3 classes; Team, Player and Coach.
Open your diagram creator and select the 3-tiered class box label the top box with the name of each class.

Step3: Add attributes.
Below the class name, in the middle box, is where you’d put attributes, which are the structural features and descriptions of a class.

For the Team, we’d have attributes like name, city and division.
For Player, it would be name, position, jerseyNumber.
And for Coach, we can say name, role, experience.

After each attribute goes a colon followed by the type of data. For example, “String” would be used for most text and “Integer” for numbers.

Step4: Add methods
Also referred to as functions or operations are the behavioral features of a class, or what that class does.

In other words, they define what actions or operations can be performed on objects of that class.

For our NFL example, it might look like this:
Team: playGame(), hireCoach()
Player: playGame(), train()
Coach: trainTeam(), makeStrategy()

The () represents a function that would be programmed at a later time.

Note that both attributes and methods appear in list form, with a lowercase letter and no space between words.

As for those symbols: +,-, # or ~, they’re the visibility of that attribute or method and its access privileges to other classes.

– = Private, meaning no accesses from other classes
+ = Public, accessible to other classes
# = Protected, accessible by the same class or subclasses
~ = Package, can be used by any class in the same package

Step5: Show relationships
Relationships can be defined in quite a few ways in class diagrams. To show the most important ones, we’ll expand our NFL example a touch throughout this section.

Inheritance
Also known as generalization, this is a relationship where a subclass inherits attributes, methods and other relationships from a superclass.

In the NFL example, if we add the classes of Quarterback, Running Back and Left Tackle, they would inherit the attributes and methods of the player class. Player would be the superclass or parent in the relationship and the position would be the child, or subclass.

If we change an attribute in the player class, all those connected to it will inherit the change. In the class diagram,
inheritance is shown with a solid line and hollow arrow.

A note about classes here, if we do add a bunch of positions, the player class turns into what’s known as an abstract class.
That’s one that serves as a blueprint for others below it and provides common structure and behavior.

The way to indicate this on our NFL diagram is either <<Player>> ;or with italics, Player.
Association
Sometimes called simple association, this is a relationship that indicates one class is related to another but not necessarily dependent.

For example, in the NFL, coaches are associated with teams, teams can have multiple coaches and other teams have coaches.

We display this with a solid line connecting the associated classes.

The relationship can also be directional, if that’s the case, you can use a filled-in arrowhead with the head ending at the smaller class.
So team would point and connect to player.

Aggregation
A special type of association, aggregation is where one class contains, or is composed of, other classes. A whole and its parts.

These parts can exist independently of the larger class and may be shared among multiple wholes.
With our football example, a team will aggregate players, but players can still exist on other teams or as free agents.

The shape of this connection is a hollow diamond attached to the “part” with a solid line going back to the “whole” or class.
Composition
On the flipside is composition, where a part cannot exist without the whole, or superclass.

Expanding the example further and adding a couple more classes; stadiums and snack bars. If the team’s stadium is torn down,
the snack bar can’t exist.

This is drawn with a solid line and filled in diamond at the superclass, or stadium in this case.

Dependency
This is a relationship where one class relies on another in some way, often through method parameters,
return types or temporary associations.

Coaches and players are related in this way, where the coach depends on the performance data or behavior of players
to make strategic decisions.

We’d show this with a dashed line and an open arrow.

Step6: Add multiplicity notation (if necessary)
Multiplicity specifies how many instances of one class are associated with instances of another class in an association.

For our NFL example, the player and team association would have multiplicity notation to indicate there are multiple players on a team.

The way we show that on the structure diagram is as follows:
– 0..1 = zero to one
– 1 = exactly one
– 0..* = zero to many
– 1..* = one to many
– n..m = specific number range

Note: a real-world class diagram for the NFL would involve way more classes and relationships to capture the full complexity of the league, including divisions, conferences, stadiums, game schedules and oh so much more.

Step7: Add multiplicity notation (if necessary)
Once you have everything in place, it’s time to do what you should do with every diagram,
map or document you put together; review it and edit as needed.

The goal is to visualize your system as clearly and cleanly as possible and now you’re equipped to create your own class diagram.

Credit : https://slickplan.com/blog/how-to-make-a-uml-diagram

Messenger
Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.