3.7

## University of Strathclyde

Skip to 0 minutes and 1 secondThe state transition diagram shows you the time dependent behaviour of the system. So those functions and data-- what happens to them and when, but it does not cover the structure or the functions of the system. In some sense, this is the simplest thing in the world, because you just need to explain all the states, and how you can get from one to another. As you will see, this is not exactly how it works out in reality. There are, again, four components of the state transition diagram. The first is obviously the state. The state is a set of conditions that describe the system at any moment in time.

Skip to 0 minutes and 48 secondsSo for example, you have your coffee machine, it is in the state of graining your coffee, then it is waiting for you to stop it, or it is waiting for the coffee to run out. It will not stop otherwise. So in this case it is doing something, but it is waiting for something to happen as well. The second step is the transitions, which means getting from one state to another. Now, what is important about the transitions is that they have to be valid. So from some states you can get to some other states, but not from any state to any other state. And you probably start thinking about now the right way that this may actually make things complicated.

Skip to 1 minute and 31 secondsYou will see this is not complex, this is only complicated. Difference is that the complex means that it is really, really difficult, there are very messy relationships between different entities. Here, everything is simple, but it is so many of them, so many of them, that you might lose count of it. And there are two components that are a little bit different than the previous two, and both of them are displayed close to the arrow that represents the transition. And they are basically attributes of that. One is called the condition. I prefer to call it a trigger, because this is what triggers the change of the state. So this is what triggers the transition.

Skip to 2 minutes and 23 secondsFor example, if you press the switch on button on your coffee machine, then it will start warming the water. The condition, the trigger, was that you pressed that button. And the other part is called the action. It is something that the system delivers back to you, or does a calculation of data that it will store for later use. Now, if we want to look at the whole story of these state transition diagrams, then what we need to know is that there is always, in any sort of state transition diagram, only one single initial state. If you cannot identify an initial state, then you just add idle, and you almost cannot be wrong.

Skip to 3 minutes and 13 secondsSo that's the state in which the system is nothing is going on. Now, there can be many, many different final states. So the whole process of the system can end up in different places. Now, if you, for example, want to write down or draw a diagram of the states of your mobile phone, with a very, very, very small font, you would be easily covering Glasgow-- we are in Glasgow now-- so you would be covering the whole Glasgow just to describe all the states of your mobile phone. So it means that you will have to have stages of the state transition diagram if you are actually making one. What is the best descriptor of how incredibly complicated this can be?

Skip to 4 minutes and 7 secondsIf you are familiar with events like the blue death-- so it means when your computer goes frozen and it displays a blue screen. That is actually an undefined state, which means that your computer entered a state from which it cannot exit. And then it stays there. What is really remarkable that, having talked to a few top computer scientists in the world, they said that about 97% of the failures in computers are because the state transition diagram is not good. But imagine if I said that your mobile phone would cover the whole Glasgow, it means that your laptop would cover the whole world. And even then you might not notice all of them.

Skip to 4 minutes and 57 secondsSo you need to pay attention if you're doing this that all the states are defined, that you can exit from any state into which you can enter, and that all the transitions that you consider are valid, so that there is a possibility to go from that one state to that other state. It is also important that you have different ways of approaching this work of building a state transition diagram. One is typically that you start to map all the states, and then you try to figure out from which states you can get into each other states. The other is what they call the avalanche approach.

Skip to 5 minutes and 38 secondsSo you take one state, then you say, OK, from this state, where I can go? I can go here, here, here, and here. Then you take one of these from this state. Where I can go? I can go here, here, here. Then you take one of those and so on, and you'll follow one line. Then you get one step back, follow the other line. Two steps back and so on. What is remarkable is that if you think about a system of any decent complexity, it would normally take you forever to accomplish this. So it is a very, very complicated thing, although the state transition diagram itself is very, very simple.

Skip to 6 minutes and 16 secondsSo I will show you now this ATM machine example that I mentioned. We start from the idle state. This is an old fashioned ATM machine, it means that it has a little bit fewer functions. And in the idle state, you actually need to push a button in order to start the first process. Once you press the button, this triggers a transition from the idle state to a different state, and it goes over to the waiting for card state. At the same time, on the screen it displays for you "insert card". Now, you could expect what the next trigger would be. It is that you insert the card.