A state model describes the timely behaviour of the class objects over a period of time. A state model has multiple state diagrams where each state diagram describes a class in the model.
State model shows these changes in the object with the help of states, events, transitions and conditions. Events are the incidents that occur to the object at a particular time whereas the state shows the value of the object at a particular time. In this section, we will discuss state model along with its elements and importance.
Content: State Model in Object Orientation
What is State Modelling?
A state model describes the life of the objects over a period of time and it also defines the sequence of operations that are implemented on the object over that period of time. Further, the state model also explains what kind of operations are implemented, on what they are implemented and how they are implemented?
So, on an, all the state model thereby represents behaviour and control aspect of the entire system. The state model is comprised of several state diagrams. Each state diagram represents a class with the aspects important from the application point of view. The figure below will show you the sample state diagram that shows the relation of events to states which we will discuss in the section below.
Elements of State Model
As we have learnt above that the state model consists of several state diagram where each state diagram represents a class. A state diagram describes the relation between events and states which are the significant elements of the state model. 4Let us discuss them one by one.
Events
Events are the incidents that take place at a particular time. For example, a train departs from the station, a person switches off the button and so on. In the problem statement, you can identify events as the verbs in past tense or you can identify them as the beginning of some condition.
The two non-relating events are said to be concurrent if they don’t have an impact on each other. Events can also be the error condition like the transaction aborted, timeout condition. Well we have several types of events but here we will discuss some common type as given below:
1. Signal Event
The signal event describes, sending and receiving of information from one object to another at a particular time. This event specifies one-way transmission.
2. Change Event
A change event is an event that occurs whenever a boolean expression is satisfied. This boolean expression is checked continuously and whenever the expression result changes from true to false or from false to true the change event occurs.
Although we know that the change event is not checked continuously but it should be check so frequently that it appears continuous from the application point of view. The UML representation of the change event is as follow:
when(room temperature < heating point)
In UML the change event is expressed using ‘when’ keyword followed by the boolean expression.
3. Time Event
The time event is the event that occurs at a specified time or after the specified time elapsed. The absolute time event is represented in the UML using the ‘when‘ keyword followed by the parenthesis with a time expression. The Time interval event is represented by the ‘after‘ keyword followed parenthesis with expression evaluating the time duration.
when(time = 18:30)
after(10 seconds)
States
The state represents the values of the attributes of an object at a particular time. Thus, the state defines the behaviour of an object at a point in time. Like, the water at a point in time can either be in a liquid state or solid-state or gaseous state.
A state can be identified as a verb with the suffix of ‘ing’ for example, eating, waiting, sitting. In UML the state of an object is represented with the round box containing the state name.
While defining the state of an object, attributes whose values do not have an impact on the state of an object are ignored. An object has a finite number of state and at a time it can be in one state only. As an event occurs the object changes its current state depending on the type of event occurred.
The difference between the event and the state is that the event represents a particular point in the time scale whereas state represents an interval in the time scale.
Transitions and Condition
When an object changes its current state to another state it is termed as the transition. The source state and the target state of a transition are usually different but, in some cases, both source and target may be the same.
Transition triggers the change in the original state of an object on the occurrence of an event. Thereby the target state or the next state of the object depends on the object’s original state and the event to which the object’s original state has responded.
The occurrence of the transition also depends on the guard condition which is a boolean expression. The guard condition is checked only once when an event occurs and if it turns out true the transition takes place.
State Diagram
The state diagram in a state model represents the order of the events which causes the change in states sequentially. A state diagram is basically a graph, where every node in a graph denotes the state and every line connecting the nodes are the transitions that respond to an event and cause changes in the state.
There are multiple state diagrams in a state model and each state diagram would represent a class and its timely behaviour, important from the application point of view. The diagram below represents the state diagram for a chess game.
In the above diagram, the rounded boxes with a name are the states. The arrowed lines are the transitions and arrowhead points to the target state. The labels over the transition lines are the event that lets the transition and change of states occur.
Each state diagram in the state model is presented in the rectangular frame and the name of the corresponding state diagram is written in the pentagonal tag at the left corner of the rectangular frame as you can see in the figure above. Guard conditions are optional are if required are written in square brackets just beside the events.
Key Takeaways
- State model shows the behavioural aspect of the object over a period of time.
- A state model has several state diagram each for a class.
- Elements of state diagram are events, states, transitions and conditions.
- Events are the incidents that occur at a point in time.
- The state is the value of attributes of an object at a particular point of time.
- Transition is the change of state from one to another.
- The guard condition is the test which when turns true the transition occurs in the state.
- The state diagram shows the sequence of events and the sequence of changes occurred in the states due to events.
So, this is all about the state modelling which represents the changes that occur in the state of the objects over a period of time. We have discussed the elements of state modelling along with the examples.
Leave a Reply