Start Diagramming!

<- Previous

5c. UML Elements - Operation

Now it's time to introduce some behavior into UML Class Diagrams and talk about the "Operation" element.

What is a Operation?

"An Operation is a BehaviorialFeature...An Operation may be directly invoked on instances of its featuringClassifiers."

Operations specify the behavior of Classes. You can think of Operations as method signatures that specify the name, parameters, return type, and other parts of that method. Methods can be invoked by passing argments which may return a value or values.

Operation "type"

An Operation's "type" is the same as the return type Parameter if defined. This return type appears after the Operation name behind a ":" character.

Operation "visibility"

An Operation has a "visibility" which determines to what level other elements are able to see and access data from that Operation. An Operation has a visibility of either public, private, protected, or package.

Operation visibility
Operation "visibility"

"static" Operations

An Operation can be "static". When an Operation is static, it can be invoked from the Class itself instead of from an instances of that Class.

A "static" Operation is indicated by it's name being underlined.

Operation static
Operation "static"

"abstract" Operations

An Operation can be "abstract". An abstract operation indicates it does not have an implementation and should be implemented by a specializing Class. We will talk more about specializations later.

An "abstract" Operation is indicated by it's name being italicized.

Operation abstract
Operation "abstract"

Operation "parameters"

Operations define zero to many "parameters". A "Parameter" is a definition of an argument that you would pass when invoking that method. Parameters themselves have a "type", a "multiplicity", a "direction", a "defaultValue", and many other things.

An Operation's parameters are shown in between opening and closing parenthesis "(" and ")" along with their "type" and other details about the parameter.

Operation parameters
Operation "parameters"

How do you know when to define a new Operation?

To determine the Operations a Class should have when modeling, think of the verbs that an instance of that Class might do (“convert”, “do work”, “calculate total”). Then combine those words together to make those as the operations of the Class ("convert", "doWork", "calculateTotal").

Sometimes there are things could be reasonably modeled as both a Property or an Operation. For example, "calculateTotal" could be modeled as a property called "total." So, should you choose a Property or an Operation? Sometimes it's a matter of preference and may come down to the modeler. But one suggestion is to ask whether that information might need to be derived from other information. In our example, if the "total" should be derived from the "tax", "promo", and "fees", it may make sense to model the "total" as a derived Operation that we previously mentioned ("calculateTotal").

Comparison to Object-Oriented Programming Languages

Operations sometimes are referred to as “method signatures” or “function signatures” in Object-oriented programming languages. When modeling using UML Class Diagrams, normally you would not need or want to define the implementation of the method in the model itself, but instead implement in code, but it is useful to define the signature in the model.

Abstract Syntax

To illustrate what an Operation is, UML provides abstract syntax which we have recreated in UML Class Diagrams.

Operation Abstract Syntax
Operation Abstract Syntax
Operation Abstract Syntax Inherited Attributes
Operation Abstract Syntax Inherited Attributes
Operation Abstract Syntax Inherited Operations
Operation Abstract Syntax Inherited Operations

Next ->