Now we have talked about all the necessary components for drawing a state machine diagram. Now let's take a look at this problem statement, and try to come up with a state machine diagram for this update section in this ASU course registration system. Now to construct a state machine diagram, you have to ask yourself the following questions. What are the possible states that the class can be in? What determines the state that the class is in, and also to what events, does each state respond, and what happens when the events occurs, et cetera. In this state machine diagram for a section, we would need an initial state and also a final state. Now we have to think about what are the possible states, that we can have within this class section. For a particular class section, may be either available, so we will have the state call available or it may be full, that means we don't have any seats available within the section. Or eventually the class or the section may be offered, after the [inaudible] period, if we have enough students in the class, then we can offer the class. Then finally, if we don't have enough students, then we may cancel the class. These are the possible states that we can have within this state machine diagram. Then when we construct a section, we're going to go from the initial state to available, and we will set the number of enrolled students to be zero because initially we don't have any students in the section. That's why we initialize the variable to zero. Then according to the prompt statement, when we have 40 students in the class, then the class becomes full. Now we may move from available to full, and we have a change event ran and law is equals to 40. Then we're going to move from available to full. Then when the class section is full, we may go back to available, it's possible. This is going to happen when we drop student, when we call this operation to drop student, then we have to unregister the student. Then we go back to the available state. Then when a class is available, notice that when registration closed, and the number of students that we have within the section is bigger than or equals to 10, then we going to offer that class section. Then when do we go into cancel? When registration closed and the number of students that we have within the class is less than 10, then we will cancel the section. Then finally, after we cancel the section, we have to destroy the section. This is the state machine diagram that we have for this class section, within the ASU course registration system. Now let's say we know exactly what operations that we have within the class, then we can include more information within the state that we have within this state machine diagram. For example, under the available state, we may add student or we may drop student. When we add student, and we have to register the student. When we drop student, we have to unregister the student. Also when we cancel the section, these are the things that we have to do. For example, we have to unregister all the students, and also we have to delete the schedule. Then finally, you also have to delete the section itself. This is the state machine diagram for the section class in the ASU application domain. It's also possible to have composite state machine diagram, that means it's nested, and we have a state machine diagram within an artist state machine diagram. We may have sequential composite state machine diagram, that means an object is in exactly one state in one of the nested state machine diagrams, or concurrent composite state machine diagrams. That means an object is in exactly one state in each of the regions of the state machine diagrams. I'm going to show you some examples. This is an example of sequential composite state machine diagram, and you can see that under the state, we're going to have another state machine diagram, and I can indicate that this is a composite state. That means within the state, we're going to have another state machine diagram, and this is what we call the super state, and this is a sub-state. We may have transition going from the superstate, a state from the superstate into the boundary of the substate. That means we're going to go into the initial state of the composite state machine diagram. We may also have a transition going out from the substate. That means we're going to exit this composite state machine diagram and then go into a particular state within the superstate. So now using this composite state machine diagram, we can capture the more complicated behavior within this state forward. What do we mean by having a transition going from the boundary of this forward state to the first gear. That means, no matter where in the first gear, second gear or first gear whenever we stop the car, we are going to go back to the first gear. Then we can shift up or shift down and then go to a different gear within this forward state and this is what we mean by composite state machine diagram. We have one state machine diagram within another state machine diagram. We may also have concurrent composite state machine diagram. Again, this incomplete state, we have an icon here and this icon denote that this is a composite state machine diagram. Now you can see that within this incomplete state, we have to do several things at the same time concurrently in order to, for example, pass the course. Let's say while you're in this incomplete state, you have to complete all the labs, you have to do the term project, and also you have to take the exam. You have to get all this thing done before you can go into the passed state. Otherwise, if you cannot get some of them done, then you will fail the course and this is what we mean by concurrent composite state machine diagram. Notice that in this composite state machine diagram, we have different regions. One region for the lab, another region for the term project, and another region for taking exam. That means an update would take one of the states within each region. For example, for the lab part it's going to be at Lab 1 for term project and taking exam is going to be at the initial state. This is what we have talked about in the example. We may have a transition going into the boundary of a composite state or going out from the boundary of a composite state. It's also possible that we may have transitions that go directly from within a composite state region to an outside region. That means we go directly from the substate to the superstate. A transition may have multiple source or target states and this represent a synchronization or spreading of control and I'm going to show you an example of a transition that have multiple source and target states. This is an example of concurrent composite state machine diagram with synchronization and when we have a bar, then that means we have synchronization. What do we mean by having a bar with multiple target states? For example, this bar is going to point to A1 and B1 at the same time. This bar actually means that we're going to go into A1 and B1 at exactly the same time. That means synchronization. We have a bar here with multiple source states. That means we have an arrow going from A2 and also from B2 at the same time. Again, this means synchronization. That means we have to wait until both A2 and B2 have finished before we go into clean up. This bar here just means synchronization. They have to start at the same time and finish at the same time. Now what if we don't have the bar? Then that means we are not doing synchronization. We've done synchronization then that means we either follow this path or the other path, but not both at the same time. Why? Because a state machine diagram is going to be always deterministic. That means we can always determine the states that an update is in at a particular time and we know that a transition is instantaneous and cannot be interrupted. That means we're going to follow one of the transitions at one time. That means we're going to follow either this path or the other path, but not both at the same time. Without synchronization that means we will either go into this path or the other path, but not both at the same time. But using synchronization it's possible that we're going to go into the two regions at the same time. That's why here I say that only one of the two transitions will be taken if we don't have synchronization. Some of you may ask, do we have to draw a state machine diagram for every class that we have within the software system? Yes or no? I would say no because we have so many classes within the software system. If we draw a state machine diagram for every single class that we have within the software system it's going to take a long, long time. That's why here I say that it's not necessary to produce a state machine diagram for every class within the program. But we should draw a state machine diagram for classes with significant dynamic behavior. If the behavior within the object is complicated then we may have to draw a state machine diagram to clarify the behavior within the object and that's what I want to cover in this lecture.