Basic components of a class diagram
Depending on the context, classes in a class diagram can represent the main objects, interactions in the application, or classes to be programmed. To answer the question "What is a class diagram in UML?" you should first understand its basic makeup.
- Classes: A template for creating objects and implementing behavior in a system. In UML, a class represents an object or a set of objects that share a common structure and behavior. They're represented by a rectangle that includes rows of the class name, its attributes, and its operations. When you draw a class in a class diagram, you're only required to fill out the top rowâthe others are optional if you'd like to provide more detail.
- Signals: Symbols that represent one-way, asynchronous communications between active objects.
- Data types: Classifiers that define data values. Data types can model both primitive types and enumerations.
- Packages: Shapes designed to organize related classifiers in a diagram. They are symbolized with a large tabbed rectangle shape.
- Interfaces: A collection of operation signatures and/or attribute definitions that define a cohesive set of behaviors. Interfaces are similar to classes, except that a class can have an instance of its type, and an interface must have at least one class to implement it.
- Enumerations: Representations of user-defined data types. An enumeration includes groups of identifiers that represent values of the enumeration.
- Objects: Instances of a class or classes. Objects can be added to a class diagram to represent either concrete or prototypical instances.
- Artifacts: Model elements that represent the concrete entities in a software system, such as documents, databases, executable files, software components, etc.
Sections within a class
The standard class is composed of three sections:
Upper section
Contains the name of the class. This section is always required, whether you are talking about the classifier or an object. The class name should:
- Start with a capital letter.
- Be formatted with bold typeface.
- Be centered in the upper section.
- Be descriptive.
Middle section
Contains the attributes of the class. Use this section to describe the qualities of the class. This is only required when describing a specific instance of a class.
Bottom section
Includes class operations (methods). Displayed in list format, each operation takes up its own line. The operations describe how a class interacts with data. The text in the bottom two sections is usually aligned to the left and typed with lowercase first letters.
Member access modifiers
All classes have different access levels depending on the access modifier (visibility). Here are the access levels with their corresponding symbols:
- Public (+)
- Private (-)
- Protected (#)
- Package (~)
- Derived (/)
- Static (underlined)
Member scopes
There are two scopes for members: classifiers and instances.
Classifiers are often recognized as static, meaning that attribute values remain the same in all instances, and method invocation doesn't affect the instance's state. In comparison, instances contain methods that can change the instance's state and attribute values that may vary between instances. To indicate a classifier, just underline its name; leave the text to indicate an instance.
Interactions
The term "interactions" refers to the various relationships and links that can exist in class and object diagrams. Some of the most common interactions include:
Inheritance: The process of a child or subclass taking on the functionality of a parent or superclass, also known as generalization. It's symbolized with a straight connected line with a closed arrowhead pointing towards the superclass.

In this example, the object "Car" would inherit all of the attributes (speed, numbers of passengers, fuel) and methods (go(), stop(), changeDirection()) of the parent class ("Vehicle") in addition to the specific attributes (model type, number of doors, auto maker) and methods of its own class (Radio(), windshieldWiper(), ac/heat()). Inheritance is shown in a class diagram by using a solid line with a closed, hollow arrow.
Bidirectional association: The default relationship between two classes. Both classes are aware of each other and their relationship with the other. This association is represented by a straight line between two classes.

In the example above, the Car class and RoadTrip class are interrelated. At one end of the line, the Car takes on the association of "assignedCar" with the multiplicity value of 0..1, so when the instance of RoadTrip exists, it can either have one instance of Car associated with it or no Cars associated with it. In this case, a separate Caravan class with a multiplicity value of 0..* is needed to demonstrate that a RoadTrip could have multiple instances of Cars associated with it. Since one Car instance could have multiple "getRoadTrip" associationsâin other words, one car could go on multiple road tripsâthe multiplicity value is set to 0..*
Unidirectional association: A slightly less common relationship between two classes. One class is aware of the other and interacts with it. Unidirectional association is modeled with a straight connecting line that points an open arrowhead from the knowing class to the known class.

As an example, on your road trip through Arizona, you might run across a speed trap where a speed cam records your driving activity, but you won't know about it until you get a notification in the mail. It isn't drawn in the image, but in this case, the multiplicity value would be 0..* depending on how many times you drive by the speed cam.
Â