How to model two interacting state machines of two different classes? - uml

As far as I know, UML state machines model the behavior of one element, for example the behavior of one class.
I wonder how to model state machines with two classes which interact.
The state of one class depends on the state of the other class and transition of one state machine may trigger transition of the other state machine.
Do I have to use UML effect? Could an UML effect of one state machine trigger a transition of another state machine?

You can send events between classes to trigger transitions, something like this, for example:

Related

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

UML Multi-Instance State Machine Visualisation

I was wondering if you could help me clarify two aspects regarding multi-instance state machines.
First question
Consider an example state machine SM1 containing one state A:
On the left, transition start creates a new instance of the state machine. Transition stop terminates the instance.
There can be multiple instances of state machine SM1 running in parallel, e.g. 5 instances.
Now, what I want is a transition that would terminate ALL state machine SM1 instances that are running at the given time.
E.g. we create five state machines A and then transition stopALL would terminate ALL of them at once.
Is such behaviour permitted by UML specification? If yes, is there a graphical notation to unambiguously represent such a behaviour? I could not find the answer in the UML specification document.
Second question
Consider a multi-instance state machine SM2 with state A and one transition startStop:
The behaviour of the transition is as follows: upon firing, the transition creates a new instance of SM2 and terminates an existing one.
Is such behaviour permitted by the specification? Is there an unambiguous graphical way to express such a behaviour?
There is no special UML method but standard UML tools are absolutely sufficient. You need to broadcast a terminate signal (on state machine diagram you can represent it by behaviour on a transition that should terminate other instances). Then you just need to model that on terminate reception the state machine goes to final state.
Terminate All Example
Note that the behaviour after slash (/) is a behaviour invoked on a state transition i.e. when a state machine changes it's state into final the behaviour sendStopAllSignal is invoked which in turn should be described on a class diagram (with probably corresponding activity diagram)
Similarly you need to have a receiveStopAllSignal behaviour included in class diagram.
Terminate Existing At Start
This is similar situation - you need to have both sendStopSignal and receiveStopSignal modelled elsewhere.
Note however that such naming convention (sendAbcSignal for behaviour of sending/broadcasting signal Abc and receiveAbcSignal for behaviour as a reaction to Abc signal reception) is quite common, useful and self-explanatory (i.e. you probably won't model a separate action diagrams for those behaviours unless some extra logic is needed there).

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.

In UML, does an object's state machine define the object's lifecycle?

In UML, does an object's state machine define that object's lifecycle?
That is, do transitions from the initial state to an ordinary state create the object, and transitions to the final state dispose of that object?
Generally yes - at least that's probably the most common way of using them.
It's not mandated that way in the UML spec; it allows a more general use of state machines. For example, a Final State can be used to signify the end of a behaviour thread within a region if the state machine has >1 regions. Or a state machine can be used to define a protocol instead of an object's lifecycle.
Some variants (profiles) of UML do enforce the behaviour you describe, for example Executable UML.
I'd probably turn the question on its head and ask: would it be useful to you if the state machine did define the object's lifecycle? If so then just use it that way. If you need to formalise then you could define a profile. But it's equally fine to just agree informally in your team.
hth.

Can UML state machine diagram be used to show the screen navigation?

Can UML state machine diagram be used to show the screen navigation?
Sure you can create a UML model of the UI as a state machine, for example:
Screens are states
State transitions i.e. screen changes occur on specific inputs or other triggers
Did you actually have some more specific question?
You can use state machines but it is also possible to use sequence diagrams for that. If you don't need to stick to the pure UML, there are plenty of approaches devoted to the specification of web systems that include the concept of web navigation models (with elements as pages, links,...). These approaches either use UML profiles or a completely different modeling language (as WebML)
UML is for modeling processes for an Object Oriented paradigm. State Machine actually deals with an object's state and has got nothing to do with UI navigation.
Your best bet here might be to represent that in Use-Case diagram.

Resources