How to specifiy internal operations (do/entry/exit..) in a state machine - state-machine

I'm using Enterprise Architect version 9, and I'm trying to draw a state machine diagram, in this diagram I want to draw internal operation (do/entry/exit..) as following :
I looked about a solution and all I can find is to draw a self transition and then set the "kind" of the transition to "internal", but it doesn't make any change: transition is still drawn like an external transition and thus the diagram is still wrong/looks wrong :
As I can notice it is not practicable to handle internal triggers in the operations compartment, since the "Action" type for the operation must be entry, exit, or do ("event" is not an option), nor is there any meaningful way to specify the event, since a transition is not an operation.
I'd appreciate any help to solve this.

The entry/exit/do are just stereotyped operations of the state. From the context of the state in the diagram choose Features/Operations. Here your see the Action with you desired entry/exit/do.

Related

Why DOESN'T this Star UML Sequence Diagram have the activation "rectangle" in the Control object?

Why DOESN'T this Star UML Sequence Diagram have the activation "rectangle" in the Control object? Am I doing something wrong? Should I set something in Star UML?
How can I add the activation "rectangle" in the Control object?
The simple answer is: because that's how the designers of Star UML designed it to be.
In Star UML if nothing initiates (triggers) the Execution Occurrence (that's the formal name of that rectangle) then... there is no Execution Occurrence. If you want to have it, you need to trigger it somehow (e.g. by self-referencing Initiation message).
I didn't find any option to change that behaviour. I haven't been using the Star UML for quite some time but since the free version has been abandoned earlier than I've started using it, I believe nothing has changed since.
If you're using the newer, proprietary version, you can send a request to the dev team of Star UML to add it as a functionality.
Well, this is because no tool I know of implemented sequence diagrams correctly. According to UML it should be possible to define ExecutionSpecifications (aka activations) independent of any Messages.
However, many tool vendors seem to assume, that an ExecutionSpecification must be started by a message. I can see, where they come from, since every execution has a cause. The problem is that sequence diagrams are not about causality, but about possibly occurring sequences of events. Sequence diagrams don’t mean, that this is the only possible sequence.
If we accept that the tool wants to start an ExecutionSpecification with a Message, the behavior of Star UML is consistent. Please note that a create message (i.e. messageSort=createMessage) does not call the constructor:
UML: A CreateObjectAction is an Action that creates a direct instance of a
given Classifier and places the new instance on its result OutputPin.
The Action has no other effect. In particular, no Behaviors are
executed
I know, this is about Actions, but why should a create message be different? Also, there is a constraint that stops create messages from having a signature:
signature_refer_to
The signature must either refer an Operation (in which case messageSort is either synchCall or asynchCall or reply) or a Signal (in which case messageSort is asynchSignal).
That means, you cannot reference a constructor in the create message. You will need to call the constructor explicitly. The sender of this message is the same Lifeline that created the new object. It should not be a self message, since this is not what is happening in reality and is therefore a workaround.
There is another option. You can make the class an active class.
An active object is an object that, as a direct consequence of its creation, commences to execute its classifierBehavior
Many tools show an ExecutionSpecification covering the whole lifeline for an active Class. Maybe your Class is meant to be active?
PS: Of course, this is not completely correct, since the classifier behavior also needs to be started explicitly:
A StartObjectBehaviorAction is a CallAction that starts the execution […] of the classifierBehavior of an object
That means, it doesn’t start automatically. We need an ActionExecutionSpecification to start it. Very few tools support this :-(

State Machine Diagram VS Flowchart

What are the differences and similarities between the state machine diagram and flowchart?
So far I found that the state diagram shows us the actual change in the state, not the process or commands like in the flowchart.
In a state diagram, the nodes are states and the arrows correspond to something that happens that triggers a change of state.
In a flow chart, the nodes are actions or decisions, and the arrows correspond to the flow of control, i.e. what happens next. Flow chart are not UML. The closest UML diagram is an activity diagram that allows you to meodell more precisely everything you can model with a flow-chart and more (since the arrows can also represent an object flow).
Both can be complementary: an action/decision in a flow-chart could trigger events that cause changes of state. But it's not necessarily one for one: an action may cause several state changes without any evidence in the flow-chart that these may happen.
Short and simplified example:
Imagine an Order object. It may have the state received, delivey in preparation, delivery complete, invoiced. Each of these state tells what can happen next with the order. That'll be a topic for astate diagram.
Imagine a flowchart. These are different actions happening in sequence: Get an order from customer, Pick items of the orders from the inventory, Send items to the customer, Are all items sent?, if yes, Prepare and send invoice, if no, Find missing items and then go back to Pick items ... and continue from there.
As you see: both can tell the same story, but from a different angle with different details.
As you mentioned, a State Machine Diagram focus on display from which state to which state the execution goes based on the input.
Although a State Machine can be handled as a specialized form of a flow chart / activity chart.

SysML/UML Simulating a nested State Machine Diagram in an Activity Diagram

I am still new to SysML and UML and the simulation of those diagrams. I am using Cameo Systems Modeler 19.0.
Context: My problem concerns the continuous simulation of an activity diagram in which a state machine diagram is nested. In the activity diagram I have a Call Behaviour Action which calls the state machine diagram. After this call behaviour action there are other actions to be executed. When I simulate the activity diagram the simulation switches to the called state machine diagram without any problem. Also the simulation of this state machine diagram is fully functional.
Now onto my problem: When I finalize the simulation of the state machine diagram by choosing states, path and their triggers so that I get to the Final State Node, it terminates the simulation of the State Machine Diagram (as expected). But the simulation won't continue executing in the parenting activity diagram.
Am I doing something wrong? Are you not supposed to be able to simulate these kinds of diagrams nested like that? Am I expecting something of Cameo Systems Modeler, that this programm just can't do?
Thanks for your help! If my description is not sufficient, I will happily provide a .mdzip as a minimal example!
In UML and SysML state machines, reaching a termination pseudo state means that the scope to which the behaviour that is defined by the state machine is terminated (when it is on the top scope in the state machine diagram). This is treated in different tools diffently. Some tools use (by default or always) the state machines as mester for simulation and when the topmost state machine enters a termination pseudo state the simulation is stoped, even if it was triggered from an activity.
There is a further kind of end pseudo state for state machines, it is called an exit point. Exit points trigger that the current scope is left. And as you dont want to stop your simulation this is waht you could use. An exit point is denoted by a hallow circle with cross.
Thought: Plenty of tools deviate from whats defined in UML and SysML especially when simulating dynamic behaviours. So there might be some special options in Cameo that possibly need some consideration. One solution to some of the tools is that you create a master state machine, that triggers your master activity.
It definetely is a bug. I issued a problem and the support team identified it as such.
Update: it has been fixed

Which UML Diagram is suitable ? Two object interacting, and one is changing the state of other

My requirement : I want to come up with a suitable UML diagram based on the case which is described below. I need to know which UML will best suit this condition.
The case : Two object A and B in the form of "Application Forms" interacts with each other.Certain event in object A triggers a state change of object B.Both object interacts with each other for a Use Case.
I tried using State Diagram but it fails as here 2 object interact with each other to change the state of one object, whereas State diagram is suitable to depict state change of one object only without showing interaction with another object which is causing state change.
My requirement is to show both interaction and state change together in the same diagram.Is it possible?
Any suggestion on this which UML diagram is suitable for this?
UML uses two different diagrams for each behavior, one for State (State Machine Diagram) and one for Interaction (could be the communication diagram or the sequence diagram).
Since the Interface of a class doesn't change when it's state changes (by applying the State Pattern for example), the interaction should not really change from the perspective of the caller, sure, internally all kinds of things might be going on, but that should not really matter.
The way I'd model this is to describe which states your objects are in and which scenario will play out. That will result in a few interactions and possibly state changes. Then pick a new scenario, either using the end-state of the previous one as a starting point, or describing a new starting state.
That way each scenario is clearly defined, the interaction diagram shows how the objects interact, and multiple State Diagrams with the active state highlighted can show the changes in state and thus behavior of the different objects.
There is no diagram that gracefully combines both, since one (the state machine) is a static diagram, showing all possible options, while the other describes the interaction.
Sure you could play around with creative naming, as suggested (ObjectA/State) as your different objects in the interaction type diagrams, but it would not result in a very clear picture. What you're trying to describe here is a story, a sequence of events and how those events impact the different states of the objects. So your scenario's are the story on a high level, the communication diagrams the stories on a much more detailed level and the state machine diagram the snapshots of specific situations.
Model your states in the state diagram as such: (Object / ObjectState).
For example:
States (A/uninitialized) , (A/initialized), ...
Should work then.
State diagram, sequence diagram, communication diagram and the whole answer by #jessehouwing is fine, but I think there is an easier and more natural way:
(1) http://agilemodeling.com/style/activityDiagram.htm, Figure 3. Submitting expenses
Note that this is UML 1.4 activity diagram. Current UML notation is slightly diferent. Dashed lines represent Object flow : Chapter 3.90.2.2 Object flow ...Objects that are input to or output from an action may be shown as object symbols. A
dashed arrow is drawn from an action state to an output object, and a dashed arrow is drawn from an input object to an action state. The same object may be (and usually is) the output of one action and the input of one or more subsequent actions...
and (2) http://www.uml-diagrams.org/document-management-uml-activity-diagram-example.html
show an examples of how you can combine object states and UML activity diagram. The pictures are activity diagrams and the orange rectangles highlight points where objects with states (the part in [some state]) are shown. The purple rectangles show authors who were robbed.

if-condition in uml state machine diagram

Considering this situation:
...when an order is placed there is a check for availability, if is passed the preparation will start else the order is refused.
If the customer decides to pay with a credit card before starting the preparation the price of the order is locked on the credit card.
When the preparation is completed the order is delivered and if more than 30 minutes from the placement of the order have passed there is a discount of 50%.
My doubt is how to model the if condition in a state machine diagram, I would model it in the following way but I'm not sure it's the right way:
How should I model if conditions in a state machine diagram?
On a UML state machine diagram, conditionals are associated with transitions. The transition has a 3-part label in the form of "trigger-signature [guard]/activity". Guard is the conditional and must evaluate to true in order for the transition to be taken. All 3 parts of the transition label are optional.
From your problem description, I might define 3 states named "Waiting for Order", "Preparing Order", and "Delivering Order". There is a transition from "Waiting for Order" to "Preparing Order" and that transition could be labeled "order placed [order is available] /". I opted to leave off the activity because, from the problem description, I don't see any activity associated with this transition. You could maybe draw another transition labeled "order placed [order is unavailable] / refuse order". However, this transition would start from "Waiting for Order" and return to "Waiting for Order" because we don't change states when the order is refused. In this transition I included the refuse order activity because I assume there is some actual activity associated with refusing an order.
Alternately, I have seen transitions drawn which include a decision diamond where the arrow leading into the diamond is labeled with the trigger, one arrow out of the diamond is labeled with [guard] / activity and the other arrow out of the diamond is labeled with [else] / activity. I'm not sure whether this is technically correct UML though.
I think that the conditionals that you put in the entry activities for your Preparation and Delivery states are pretty good the way they are. Because those conditionals seem like they are associated with the activity that occurs upon entry into those states rather than any state transition.
In an UML state diagram, an if-condition should be modeled as a choice element, represented by a diamond-shaped symbol. The outgoing transitions must be marked with the corresponding conditions ("guards" in UML terminology) in square brackets. A trigger (event) and a behaviour (action) may be additionally given as described by kkrambo.
Example:
This and this gives some good advice on choices (and state diagrams in general).
This diagram (taken from here) might help:
So to answer your question, you didn't do it wrong, it's just a matter of style and readability. As far as I know, UML doesn't really define a standard way to represent conditionals. So just go with what looks best and makes sense.
It is not possible to define conditions inside of state element of state machine. Review you diagram. I think , you should some information put on diagram. For example, use choice element to define alternative transition paths. Or draw detailed diagram for "prepare order" and "payment" behaviors from Preparation and Delivery states.
It is not always possible to put all information on the exactly one diagram.

Resources