Operations

In class diagrams, an operation requests a service that a classifier or an instance of a class is called to perform. Operations are contained by classes. A classifier can have any number of operations or none at all.

Operations are implementations of functions or queries that an object might be called to perform. A well-defined operation does only one thing.

For example, you can make a Cart class responsible for adding and removing merchandise that a customer plans to buy. Then you can add an addItem() operation that adds merchandise to the cart and a removeItem( ) operation that removes merchandise.

In class diagrams, C/C++ methods map to UML class operations or behaviors.

As the figure in the following table illustrates, operations are shown in the operation compartment of a shape in a UML class diagram.

C/C++ source code UML visualization
C/C++ operations are displayed. A diagram illustrating C/C++ operations.

You can show, hide, or collapse the operation compartment, and show or hide the compartment title. You can also specify the visibility styles of operations as text symbols (such as "+") or icons (such as Image showing an Eclipse Protected visibility icon for operations.).

Related concepts
Class diagrams
Classes
Attributes
Multiplicity
Visibility
Related tasks
Changing the default for showing attribute and operation compartments
Terms of use | Feedback
(C) Copyright IBM Corporation 2004, 2005. All Rights Reserved.