Classes
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:
- Components or building blocks of a software system, such as Java™ classes, database tables for databases, and Web pages for Web applications
- Workers and artifacts of a business
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:
- The top compartment displays the class name.
- The middle compartment displays a list of attributes.
- The bottom compartment displays a list of operations.
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.