Search code examples
behaviorumlclass-diagramoperation

behavior vs operation in UML


To the best of my knowledge,

the operation is resides in the second compartment of class at class diagram.

The following is Behavior definition from UML specification(August 2011 ,page 445)

13.3.2 Behavior (from BasicBehaviors)

Behavior is a specification of how its context classifier changes state over time. This specification may be either a definition of possible behavior execution or emergent behavior, or a selective illustration of an interesting subset of possible executions. The latter form is typically used for capturing examples, such as a trace of a particular execution. A classifier behavior is always a definition of behavior and not an illustration. It describes the sequence of state changes an instance of a classifier may undergo in the course of its lifetime. Its precise semantics depends on the kind of classifier. For example, the classifier behavior of a collaboration represents emergent behavior of all the parts, whereas the classifier behavior of a class is just the behavior of instances of the class separated from the behaviors of any of its parts. When a behavior is associated as the method of a behavioral feature, it defines the implementation of that feature (i.e., the computation that generates the effects of the behavioral feature).

1)Could you please explain what behavior means in the above definition ?

2)What is the differences between Behavior and operation in unified Modeling Language(UML)?


Solution

  • Operation is a specification-only element - imagine it as the method signature in OO programming languages. It has a name and a list of parameters.

    Behavior is (among other things) what an operation (or another behavioral feature such as a reception) does when invoked - imagine it as the body of the method.

    UML actually calls "method" the behavior that defines what an operation does. Also, from a behavior (be it an activity or a state machine), the operation is seeing as the "specification".

    Note also that in UML operations can have multiple methods. What it means and what behavior(s) should be executed when an operation is invoked is up to the tool in question.

    Finally, behaviors can be state machines or activities - activities are easy to understand, as they are the equivalent of procedural code. State machines are a totally different beast, and I admit I don't understand how a state machine can be used as the behavior for an operation.