FSM Lecture 9- UML Simple and Composite states

  • Post author:
  • Post category:Blog

 

UML Simple and Composite states

 

 

State:

The state represents a distinct stage of an object’s lifecycle.

Here, object is nothing but an instance of a class or an instance of a structure.

In a programming language, there is no concept of classes, you can think of it as an instance of a structure. Basically, it’s a terminology used in OOP, object-oriented programming.

A State models a situation in the execution of a StateMachine Behavior during which some invariant condition holds. In most cases, this condition is not explicitly defined but is implied, usually through the name associated with the State (OMG® UML 2.5.1)

 

How do you arrive at fixing a state?

Map different scenarios through which an object lifecycle passes into a number of states.

 

Different scenarios of Protimer application:

  • IDLE 
  • TIME-SET
  • COUNTDOWN
  • PAUSE
  • STAT

These are the different scenarios through which the Protimer application object lifecycle passes. All these scenarios you can map into different states in a state machine diagram.

 

UML Simple and Composite states
Figure 1. Object

An application may have different objects.

Our application also definitely will have one associated object. That’s why states are associated with the life cycle of an object.

And an object is nothing but it’s a collection of a set of attributes and a set of behaviors. Attributes are nothing but structure or class member elements.

For example, there could be a few structure or class attributes in our application to track the current time, elapsed time, productive time, etc. An object also comprises a set of behaviors or methods, or you can call it member functions and those functions act upon those attributes.

What I want to clarify here is that, number states belong to the life cycle of an object. And an application may have different objects, and there could be a separate state machine model for each object.

 

How to create a state? 

  1. Draw a round-cornered rectangle
  2. Create a horizontal name compartment
  3. Give a name that is unique within the state machine diagram

 

Types of states in UML:

  • Simple State
  • Composite State
  • Submachine State

For this exercise, we will use a simple state. But composite state makes your state machine diagram much simpler, you can reduce the clutter in the state machine diagram using composite state, but we will keep that for a separate discussion.

And whenever I explain various transitions and other things while doing this exercise, all those terminologies are with respect to the simple state.

 

Simple state

A simple state is a basic state that has no substructure or internal behavior. It represents a single, atomic state that the state machine can be in at any given time. Simple states are denoted by a rectangle with rounded corners.

If a state doesn’t have any substates, transitions, regions, submachines,  then it’s a simple state.

UML Simple and Composite states
Figure 2. Simple state with name compartment
  • A simple state can have two or more compartments. 
  • The name compartment should hold the name of the state as a String. And that name should be unique within the state diagram; you cannot duplicate the state’s name. No two states can have the same name.(Figure 2)

 

Composite state:

A state which has substates. A composite State contains at least one region.

A composite state is a state that has substructure and internal behavior. It can contain one or more regions, which can contain one or more states. A composite state can also have internal transitions, which are transitions that do not leave the composite state but rather change its internal state.

Composite states are denoted by a rectangle with a smaller rectangle inside, representing the region that contains the substates.

 

Two types of composite states

  1. Simple composite state
  2. Orthogonal state (or orthogonal composite state)

A simple composite state has exactly one region.

  • By using composite states, you can express state hierarchies.
  • It makes statecharts more comprehensible by reducing the number of transitions between states.

Example:

UML Simple and Composite states
Figure 3. Example 1

S0 is a state or a simple state. It has got no regions, and it has got no substates. That means it has got no child state inside of it. It has two compartments. The first is a name compartment; the second is an activity compartment. 

S1 here is a composite state. It has got child states or substates. Whenever substates appear, it forms a region. That’s why S1 has one region identified by ‘r1’.  

As per the specification, any state enclosed within a region of a composite state is called a substate of that composite state. Here, S1 has exactly one region. That’s why it is also called a simple composite state.

 

Figure 4. Example
Figure 4. Example 2

Let’s see one more example. Here again, S1 is a simple composite state. It has one region(r1), and S1_0, S1_1, and S1_2 are substates of S1.

  • And here, S1_0 and S1_1 are simple states or simple substates of S1. 
  • And S1_2 is a composite substate of S1. S1_2 is a simple composite state, also a substate of S1. 
  • And S1_2 is a superstate of S1_2_0 and S1_2_1, and S1_2 has exactly one region. 
  • S1 has one region, and S1_2 has one region. 

 

Project requirements:

  • + button → Increment time (minutes should increase)
  • – button → Decrement time (minutes should decrease)
  • S/P button → Start/pause  the countdown; show STAT
  • When the countdown is paused, time can be modified.
  • Press the + and – button simultaneously to abort the running timer
  • Application must beep 20 times when it returns to IDLE mode
  • When the application is in IDLE mode, pressing the S/P button should show the STAT for 1 sec and auto return to IDLE mode. 

 

FastBit Embedded Brain Academy Courses

click here: https://fastbitlab.com/course1

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply