An operation is the implementation of a service that can be requested from any object of the class to affect behavior [BRJ99]. The set of all operations of a class define its behavior. The behavior of the class is defined during the analysis and design phases, and depends on the role that the class has in the domain.

A class may have any number of operations but the number of operations should reflect the behavior of the class. An operation has a name that usually is a verb or a verb phrase that represents some particular behavior of its class.

An operation has its signature that is the name and the type of all parameters used by the operation. In cases when the operation returns a result, the type of the returned value should be specified. Figure 3-2 shows the UML symbol for class Soil.


S£>soilName : String ^soilDepth : double

^getWaterStressQ : double *Soil()

Figure 3-2. Example of a class.

In UML, a class is represented by a rectangular icon divided into three compartments as shown in Figure 3-2. The top-most compartment contains the name of the class. The name of the class starts with a capital letter. The middle compartment contains the list of attributes of the class. The name of an attribute starts with a lowercase letter. Attributes have a type; attribute soilName is of the type String. This compartment is considered the "data" compartment, as the attributes hold data. The bottom compartment lists the operations or the methods of the class. A method represents a specific behavior the class provides. In the case of class Soil, the method getWaterStressQ calculates the water stress for this particular type of soil. If the method returns a result, the type of the result is defined. In some cases, operations require parameters. In this case, the type of the parameter should be defined. In the case of class Soil, the method getWaterStressQ returns a result of the type double and does not require any parameters. Figure 3-3 shows the implementation in Java of the class Soil defined in Figure 3-2.

1 package Soil;

Was this article helpful?

0 0

Post a comment