Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 323
user2019510 Avatar asked Jun 09 '13 08:06

user2019510


3 Answers

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.

like image 177
Rafael Chaves Avatar answered Sep 28 '22 19:09

Rafael Chaves


To be exact:

In UML class diagram, generally class has 3 common compartments: can be more since user defined compartments can be added to class box shape.

In practice the order of compartments:

  1. Clas Name
  2. Attributes
  3. Operations

So third compratment is used for "operations".

Behaviour: ? What you mean by Behaviour??

In OO terminology objects has properties(attributes) [ a car has color ], and behaviour (operations) [ car accelerate, stop, etc].

In UML terminology the implementation of operation is called method.

And we use Interaction (Sequence or Collaboration) diagrams to study dynamic behaviour of systems that we will build or investigate.

like image 40
Hippias Minor Avatar answered Sep 28 '22 18:09

Hippias Minor


Behavior's Specializations: OpaqueBehavior, Activity, StateMachine, Interaction For example, an OpaqueBehavior of "i = i+ 1;"

BehavioralFeature's Specification: Operation, Reception For example, an Operation of "void foo()"

Combination: A Behavior may be invoked directly, via a BehavioralFeature that it implements as a method or as the classifierBehavior of a BehavioredClassifier.

For example,

void foo()
{
    i = i + 1;
}

UML gives developer the flexibility that "assign" an operation with different "behavior" to invoke. For example, if there is another Behavior "MyStateMachine", you can simply assign Operation "foo" to invoke it.

void foo()
{
    (new MyStateMachine(this)).run();  //Create an instance of it, pass the current classifier as context of the behavior
}
like image 24
milesma Avatar answered Sep 28 '22 17:09

milesma