3

I would like to know how many Final States an UML State Machine diagram can have.

  1. In this OpenCF online book, I read this:

    Some models may have more than one initial state or more than one final state.

  2. On ModelDraw, I read this:

    Unlike Initial States, a state machine can have multiple Final States.

  3. In DavidGugea's UML book

    A state machine can contain any number of final states and terminators.

  4. Also on the State machine diagram page of visual-paradigm one can see this:

    enter image description here

So I really think there can be multiple final states in state diagrams. But I would really appreciate to have a confirmation with info from the "official UML state diagram standard".

7
  • 3
    "But I would really appreciate to have a confirmation with info from the "official UML state diagram standard". Then why don't you look it up for yourself? Searching for "uml standard" gave me this omg.org/spec/UML/2.5.1/PDF within a few clicks. On page 306 is the Abstract Syntax for a state machine, and AFAICS there is no restriction modeled on the number of final states. Commented Sep 5 at 18:53
  • 1
    I think you are being a bit hard on OP, I also read through the spec and, yes there is no specified limit, BUT there are places referring to both a final state and the final state. I dont think its unreasonable to ask for clarification Commented Sep 6 at 11:45
  • 2
    OK, page 386 : Figure 15.23 Part selection workflow example. has a diagram with two final states in a single region. (also Figure 15.44 ActivityFinalNode example) Commented Sep 6 at 12:11
  • 1
    Warning the first quote Some models may have more than one initial state or more than one final state and the second quote Unlike Initial States, a state machine can have multiple Final States. are wrong (at least ?) because there is no initial state in UML but initial pseudostate, and a pseudostate is not a state. Commented Sep 13 at 14:57
  • 1
    The third quote is also very suspicious because it is based on the sentence The execution of a region or level of states is terminated when a final state is reached which is not a quote from the UML norm (e.g. formal/2017-12-05 ) and we don't know where that come from Commented Sep 13 at 15:18

3 Answers 3

4
  • In terms of semantics, there is only one final state

  • In terms of depicting, you can draw as many final state symbols as you like, they all represent the similar one-and-only final state. I think most (if not all) UML tools will allow this.

In other words: both of these diagrams are valid and express the same meaning:

enter image description here

Hence using more than just one final state symbol in a diagram is semantically not necessary. Still it can be useful to avoid overlaps of the final transition arrows, when the state nodes before the final state are located at different areas of the diagram. It can also be useful to mark these predecessors more explicitly, because they represent the real different "final outcomes" of the state machine.

Note if you read Arseni's answer thoroughly, it seems he refers to those predecessors as "final state", not to the state represented by the black-circle symbol itself. That is a perfectly valid point of view, and it should be obvious that state machines can describe different outcomes, otherwise the notation would lose much of its usefulness.

As you asked for the official UML standard: you can find the official UML spec 2.5.1 here. Chapter 14 (about state machines) is somewhat sparse on examples, but as Ewan has pointed out correctly in chapter 15 (about activity diagrams), figures 15.23 and 15.44 show examples with more than one "final activity" symbol in a single diagram, and I don't see any reason why this should not be allowed for classic state diagrams as well.

3
  • Thanks a lot for your response AND for the reference in the OMG UML book. Also, I think the semantics vs depicting thing was the reason why I had a doubt. Thanks for the clarification ;-) Commented Sep 7 at 16:03
  • @Doc_Brown in the UML spec, I see that some diagrams do not have final state at all. So diagrams with 0 final state are also legit then. Thanks Commented Sep 8 at 12:39
  • 1
    Interesting answer. Just some clarifications: in the UML specs FinalState is a specialisation of a state, and each instance of it is a different state. So multiple final state symbols refer to different states, even if it's all leading to the same behavior. Exactly as in Harel's state machines. This is different from the connection point reference which visually provide a mean to have several symbols referring to the same state. Commented Sep 11 at 12:33
3

You already have the answer in your own question, I quote:

A state machine can contain any number of final states and terminators.

The diagram you posted is a great example of that. The user can, in this specific case, attend a booking our cancel a booking, which leads to two possible final states.

Similarly, an UML diagram that explains how a user purchases a product on an e-commerce site may have more than one final state:

  • Purchase is made.
  • The user cancels the purchase.
  • The workflow times out (for instance if the user leaves the website before competing the purchase).
  • The user encounters a technical error that prevents the completion of a purchase (such as the inability to perform the actual payment).
4
  • it should be noted that "exit points" are also used Commented Sep 6 at 11:46
  • 1
    Well, what do you think are the "final states" in the diagram - the states "Attended" and "Cancelled", or the "final state symbol", the filled bordered circle? Because, I think for the latter, there is no semantical difference between a diagram which contains only one of the filled circles or multiple ones. Drawing multiple circles instead of one is just sometimes easier to draw, because it can avoid overlapping arrows to the final state symbol. Commented Sep 6 at 19:00
  • 1
    A very interesting question! Personally, I understand it as the combination of the filled bordered circle and the state that immediately preceded it. That is, it is not just important that the process finished, but it is also important how it finished. But maybe the UML standard would disagree with me, which would invalidate my answer here. Commented Sep 6 at 20:50
  • the problem is A state machine can contain any number of final states and terminators is deduced from a quote not from the UML norm, see my comment Commented Sep 13 at 15:21
3

There are a couple of interesting answers already. But you seem to look for a formal answer, which can only be found in the UML specs, and your quotes are from authors who have their own interpretation of the UML specs. This is why I add this answer for the records, with some formal references.

The UML 2.5.1 specifications are ambiguous about your question. Indeed, several statements suggest there should be one final state, using a singular pronoun or a determined article. But several places use an undetermined article, suggesting that it's one final state among several.

Examples of wording with singular pronouns and determined article, suggesting a single final state:

14.2.3.2: (...) Each Region owns a set of Vertices and Transitions, which determine the behavioral flow within that Region. It may have its own initial Pseudostate as well as its own FinalState.

14.2.3.4.4: (...) when the State has not been entered before (i.e., no prior history) or it had reached its FinalState, [note: it doesn't say "a FinalState"]

14.2.3.4.5: (...) the most recently active substate is the FinalState (...) *[note: it doesn't say "a FinalState"].

14.2.3.4.7: (...) Similarly, a submachine Statemachine can be exited as a result of: reaching its FinalState, (...)

Example of wording suggesting possible existence of multiple final states are mainly present in the explanation of how the state machine and its transitions work:

14.2.3.8.3: (...)

  • if the State is a composite State, all its orthogonal Regions have reached a FinalState [note: it doesn't they "their FinalState"], or
  • if the State is a submachine State, the submachine StateMachine execution has reached a FinalState. [note: it doesn't say "its FinalState"]

Moreover, the abstract UML syntax defines FinalState as a special kind of State. So there could be several instances of it, including in the same state machine - and it would formally be different states not just visual cues of the same state). The UML specs absolutely do not constrain the number of final states in a region, whereas such a restriction is explicitly specified for the initial pseudo-state (section 14.5.8.6, constraint initial_vertex: "A Region can have at most one initial Vertex") and in many other places of the specs where a maximum matters (e.g. composite aggregation where an instance of a classifier cannot be at the same time in two different composite aggregation).

Considering that what is not forbidden is allowed, you can therefore assume that it is allowed to have several FinalState per state machine Region. This is apparently also the interpretation of most UML tool makers who leave flexibility about the number of final states.

The fact that the UML specifications explicitly refers to be an object oriented variant of David Harel's state charts, and that these have no constraint either on the number of final states, only reinforces this understanding.

5
  • Thanks for your response. So No ( 0 ) final state is also allowed, right? Commented Sep 12 at 13:09
  • 1
    @Pascal it is definitively valid, as there are no constraints on minimum either. There is a statement about initial statement that explains that in absence of an initial state, the region's behavior is not defined. The specs offers several alternatives, one of which is that nothing happens in the region. There is no such explicit clause on final states. So the risk is that your machine never completes (e.g. if one region would have a final state, but an orthogonal region does not, the machine would stay forever active). However I have to cross check the section on execution to confirm Commented Sep 12 at 18:45
  • 1
    @bruno thanks for the hints. Apologies for my colloquial "initial state". About the quotes, I fully agree. This is what I meant with "your quotes are from authors who have their own interpretation of the UML specs". Commented Sep 14 at 13:49
  • 1
    @Pascal After verification, I confirm my comment above. In absence of a final state, and assuming the last active state completes (it's not necessary the case, e.g. if it had a do action that never completes) the machine would just stay active on that state waiting for events that can be processed. Exceptions are if an exit point allows to leave the machine, or a terminate pseudo-state ends it, or equivalently if the instance of the behavioured classifier gets destroyed. Commented Sep 14 at 15:07
  • 1
    Very good answer. I want to add, that it really makes sense to have multiple end states. They are real states, so another object could ask what state the machine is in. This way it could for example distinguish the failed and successful state. On the other hand, it often is a mistake to put an end state at the top level. If this is modeling some software system, it would mean that it never can change to another state once it reached it. Which means the system can only be revived by rebooting. Commented Oct 9 at 10:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.