Classes

Classes are Unified Modeling Language (UML) diagram elements that represent abstractions of an object or set of objects that share a common structure and behavior.

A class identifies the attributes, operations, relationships, and semantics that instances of the class possess. Every object that instantiates a class usually provides its own attribute values. Attributes are also called variables, member variables, properties, and fields, but are usually implemented as variables. In a diagram, each class has properties that govern its appearance and location. Modifying properties of a class in a diagram only changes the appearance of the shape and does not affect the underlying semantics or any other shape that represents that application element.

As the following figure illustrates, a class shape appears as a rectangle with three compartments: You can show, hide, or collapse the attribute and operation compartments.
A C/C++ class is displayed.

You can use additional compartments to display other details such as constraints or signals that instances of the class can receive.

The classes in an application usually appear in class diagrams. Classes or instances of classes, such as objects or classifier roles, also appear frequently in other types of diagrams, including sequence diagrams. You can add classes to diagrams to represent the following items:

Example

An e-commerce application includes a Cart class. The class defines an itemList attribute, and an addItem operation that belong to all objects of type Cart. At run time, 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.

Related concepts
Class diagrams
Attributes
Operations
Multiplicity
Visibility
Terms of use | Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.