behavior vs operation in UML
Asked Answered
B

3

8

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

Brassica answered 9/6, 2013 at 8:11 Comment(0)
C
4

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.

Corrientes answered 28/6, 2013 at 5:2 Comment(2)
thank you @Rafael Chaves very much for clarifications,it is very helpful .Does this mean that operation can be considered as "Behavioral Feature" and the implementation is "Behavior"? and what about Behavior Classifier? I also didn't understand how a state machine can be used as the behavior for an operation. RegardsBrassica
Hi @Rafael Chaves ! I post a dedicated question for state diagram as a behavior for operation could you please check it #17390217Brassica
E
2

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.

Ezraezri answered 9/6, 2013 at 16:16 Comment(7)
thank you @Hippias Minor for your kind .I read about Behavior in the UML specification but I didn't understand it so I updated my question.Could you Please check it?Brassica
First, Are you simply learning UML or try to implement a UML tool?Ezraezri
Because those things are UML Meta Models and if you will not implement a UML tool , do not bother yourself with it.Ezraezri
If you simply try to learn UML and use it, this specification is not for you: This specfication is for tool vendors and for guys who identify standards.Ezraezri
Hi @Hippias Minor! thank you very much that's very kind of you. I am learning UML not implement UML tool.from where I should learn UML because reading specification is very difficult for me and I started reading it because It is the official document I have ever know about? and I also have a problem with limited UML example in the internet ?Any advice would be very niceBrassica
You should not learn UML from spec. For a genaral road map and references check my answer at #16547461Ezraezri
While not very convincing as a specific response to the question, this answer provides more clues about the extent of the overall (underlying?) question about what are the substantive differences between operations, methods, calls, and behavior. I believe the points made about using activities or sequences as the correct representation for behaviors is illuminating because it proves that if you can't provide a diagrammatic representation of behavior as an activity or a sequence, then you should probably conclude its not a behavior but an operation.Ecbolic
M
1

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
}
Medicinal answered 13/6, 2013 at 3:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.