Objects have behaviors, things they can do and things that can be done to them and these behaviors are modeled as operations. The UML distinguishes between operation and method, whereas many people use them interchangeably.
Operation and method
In the UML, an operation is the declaration of the signature. A method is the implementation of an operation and must conform to the signature of the operation that it implements.
Following this logic, completely abstract operations have no method. When we cover the dynamic and functional models, you will see more extensive tools for specifying methods.
Operations require a name, arguments, and a return. Arguments, or input parameters, are simply attributes, so they are specified using the attribute notation (name, data type, constraints, and default).
The arguments do not require constraints when they refer to a previously defined attribute because the constraint should already be defined in the attribute specification. Add a constraint to an argument only if the constraint is unique to the operation and not to the attribute.
The return is an attribute data type. You can specify the visibility of the operation: private (-) for internal operations of the class, public (+) for operations visible to other classes, and protected (#) to limit visibility to within the inheritance hierarchy. Given these requirements, the following notation is used to define an operation:
Let's create an example operation to determine the total amount due on an order.
The total is the sum of all line items less the volume discount. Each line item amount is the product of the unit price and discount. We need the answer back as a dollar amount.
Name the operation
Identify the input arguments. All of the input information is on the Order object, so an instance of Order is the only argument. Name the argument, the data type, and use a colon to a separate the two.
Define the return data type. The data must be returned as a dollar amount, simply a number with two decimal positions.
Identify and describe any constraints. We know the rules for computing the total amount, but the notation does not provide a specification language for this computation.
Set the visibility of the operation. We know the rules for computing the total amount, but the notation does not provide a specification language for this computation.We can use the all-purpose constraint notation() to hold the text describing the computation.