All the time the same issue: what window shall I use for typing code in the Enterprise Architect: the input window at the top named “Behavior” or the input window at the bottom named “Initial Code”??
To complete the confusion: the property tab also has been named “Behavior”
The property dialog has been changed between EA 8.0 and EA 9.0, the issue has remain. Summary If you want that EA considers your code during code generation please note:
- for class operations use “Initial Code:” input window for manual coding
- for class operations use “Behavior” window for linking it to a behavior only
- for state operations use “Behavior” window only for everything
If you want to understand the reason behind that, see below for explanation:
By the way, the AMUSE 2.0 (coming soon) provides a number of really helpful validation rules, e.g. in that case AMUSE warns the user about the code will be ignored by the code generation
Is there any logic at all in that? Yes it is logically and the reason is the definition of behaviors and operations in UML. So what is the relation between behaviors and operations and how EA does support that concept? Per definition a classifier (e.g Class) may have operations and behaviors:
- An operation = method declaration - like method declaration in C++ header files
- A behavior = method definition – like method definition in C++ cpp files EA supports 4 behavior-types : state machine, activity, interaction (e.g. sequence) and rule flow.
That means you have two ways for definition of the operation behavior (implementation):
- using “Initial Code:” input window for manual coding (like method definition in header files C++)
- using “Behavior” window to link it to a dedicated behavior via button “Element” in EA 9.0 or “…” in EA 8.0
BUT a State within a state machine may also have operations (entry, exit, do)! For that reason EA provides the same dialog for behavior definition of state operations. What about that? The same rules? It would be too easy Because (it’s my guess) a state is an integral part of a behavior, the “Initial Code” window is useless in the dialog. => Whatever you want to do, use “Behavior” input window for definition of state operations.