Domain state model describes the behavior of the classes that express several distinct states. The domain state model also describes the constraints on the object when it in a certain state, its properties, and also the events that trigger an object to transit from one state to another state.
Not all the classes require a state diagram to express their behavior as they can be adequately defined by the list of operations they possess. Although few classes that exhibit different states require a domain state model to ease developer to understand their behavior.
To construct a domain state model, we have to follow certain steps:
- Identify classes exhibiting states.
- Identify states of the classes.
- Identify events triggering State change.
- Construct state diagram.
- Analyze state diagram.
1. Identify Classes Exhibiting States
Domain class model describes all the classes that would be required to construct the system. From the list of classes, identify the classes exhibiting distinct states in its the life cycle.
Now, the identified classes can be categorized into two sets i.e. the classes that show progressive history and the classes that show cyclic behavior. Let see what does it means.
Consider a scientific paper that would be published in a journal. It undergoes a progressive change of states like form BeingWritten, UnderConsideration, Accepted or Rejected. Even if the reviewer asks for revision then also its life would be considered as progressive.
Now, take an example of an aeroplane which keep on changing states in a cyclic order. Like UndergoesMaintenance, GetsLoaded, Fly, GetsUnloaded. Although it not mandatory that every state would occur in each cycle. Though some classes have a chaotic life cycle still, classes with states will be classified either as progressive or as cyclic.
2. Identify States
After listing out the classes with states its time to figure out the states in which the object could be in its life cycle. State of an object represents its behavior at a point in time. You have to assign meaningful names to the states of the objects.
While naming the states, be careful that the names directly describes the state of an object, not the condition of how the state occurs. You must distinguish between the states of the object on the basis of qualitative differences rather than the quantitative difference in the behavior of the object, its attribute value and associations.
It’s not possible to determine all states of an object at once without considering the events. Its clearer when you consider the events triggering the transition of states you may get some missing states while doing so.
3. Identify Events
An event is occurring of an incident at a particular point in time. This causes an object to change its state. Now, we have a preparatory list of states and observing the states you have to identify the events that trigger the change in the states.
Just try to point out the incidents that stimulate the transition in the states. Sometimes you can define an event as completing a do-activity which gets terminated when a decision is taken. The decision can be positive or negative.
Let understand this with the help of an example. Suppose a technical paper that would be published to a journal is UnderConsideration (state). Termination of this state would either be a positive state (Acceptpaper) or it would terminate to a negative state (Rejectpaper).
The completion of do activity could also lead to some other possibilities like the paper is accepted conditionally with revision. Well, these are the advanced events that could be identified over time and can be added in future.
To discover events, think about how the object can be taken to a particular state. For suppose as you lift the receiver of your telephone it would change its state from Idle to DialTone and as soon as you press a digit it enters Dialing state.
There are some events that don’t invoke state change. But to construct the domain state model we have to think about the events causing transitions in the states.
4. Construct State Diagram
Now, after identifying classes, states, events it’s time to construct the state diagram. First, you have to note down all the states in which the objects can be. After putting the states add transitions that represent the changes occurring in the state of the object.
When an event stimulates the termination of a state then usually it would have a single transition from that state to another state.
Events triggering the target state are added where they could occur and transitions are also added from those states to target states. In case an event causes different consequences for different states then you must add a separate transition for each state.
While organizing all this you may encounter new states and transition.
5. Check State Diagram
Now, it’s time to evaluate the state diagram. You have to check whether all the states are connected through the transition. If the chosen classes were progressive then verify that there is a path from the initial state to the final state.
If the chosen classes were cyclic then check whether a loop is present in the state diagram or not. Be sure that there are no dead states that terminate the loop.
A state diagram must briefly represent the life cycle of the object. If any path is missing it may discover a missing state. You must use your knowledge to evaluate the state model.
So, in this content, we have discussed the domain state model, its use and also the steps required to construct the state model.
Leave a Reply