As usual were going to illustrate these kind of diagrams by
using an example. In particular we are going to describe the state
transition diagram for part of our example, for part of
our course management system. And we're going to focus on the course
offering class. When the class is created, it enters the
initialization state, in which the activity performed is to initialize the
course. At this point, a simple case is the case in
which the class is cancelled, so there is a cancelled event.
And if that happens, the class is simply cancelled. So it
gets into this final state, which is the state cancelled. And
the activity in this case is to notify the registered students.
Obviously if this is the flow there will be no registered students.
However something else can happen when we are in this initial
state. So what can happen is that a student can register, so
in this case the add student event is triggered. And the
corresponding action is to set the count, in this case it would
be the count of students for the course offering, to one. And
there will be a change of state and the course offering will
get into this open state. And the action that will be performed
on entry will be to register the student. At this point more
students may register. So other student events might occur and notice that we
have a curve here that tells us this event will trigger this
transition only if the count is less than 10. So we're assuming
that we're not going to have more than 10 students just for lack
of a better number in our course offering. So if that
happens, if the count is less than ten so then the count
is incremented so the increment count action takes place. And the
system goes back into the open state, and the new student
is registered. Now here we have an interesting transition, because there's
no event triggering the transition, but simply the fact that the
count is equal to 10. So you can imagine this as
being a transition that is always enabled so can always be triggered,
but will be guarded. By the fact that the count has
to be exactly ten. So basically this transition will take place
only when enough students are added, such we get to count
them. Being incremented and being equal to ten and then the transition
will occur. And we will get into the closed state, in
which the class is no longer open because there are enough students
registered. And at this point, what will happen is that the
course will be finalized. So there will be this activity which performs
some operation that is needed to finalize the course. Another possibility
is that when we are in the open state, the course
is cancelled. And if the course is cancelled, in this case,
we go again to the cancel state. But here, the activity
of notifying registered students makes more sense. Because we will have
at least one registered student in this state, and therefore we'll
need to notify such student that the course offering has been
cancelled. Finally, is it also possible also to cancel a course
after it has been closed? And in this case again, the
same thing will happen. The class will reach the cancelled state and
all the students, in this case ten students, that are registered
for the course will be notified that the course has been cancelled.
So, if we look at this state transition diagram, you can
see that it's pretty easy to see what the evolution of objects
of this class can be. How they can go from their initial
state to various final states depending on what are the external events
that reach the system.