Classes

In UML, a class represents an object or a set of objects that share a common structure and behavior. Classes, or instances of classes, are common model elements in UML diagrams.

A class identifies the attributes, operations, relationships, and semantics that instances, or objects, of the class possess. Every object that instantiates a class has its own attribute values. In class, activity, component, and sequence diagrams, classes can represent the following items or concepts:

A class's name, which you should be able to derive from the vocabulary of the system that you are modeling, reflects its role, or one of its roles, in the system. As the following figure illustrates, the Diagram Editor displays a class as a rectangle with three compartments:

A class called ClassName contains a single public attribute and a single public operation.

You can add compartments to display other details, such as the signals that instances of the class can receive.

Example

An e-commerce application for purchasing items online includes a Cart class. The class defines an itemList attribute and an addItem operation that belong to all objects of type Cart. When you run the application, multiple instances of the Cart class are created, each possessing the attributes and operations that the class defines. The values of the attributes for each instance differ if, for example, one class object calls the addItem operation to add videos to its itemList attribute, while another instance uses the same operation to add books.


Feedback