READING STATECHART DIAGRAMS Figure 4.48 A Statechart diagram with events The diagram in Figure 4.48 shws all states that the bject plane can be in during the curse f its life. Furthermre, it shws the pssible transitins between the states and the events that initiate these transitins. Each bject f the class plane cmes frm nwhere (1) (initial state) and disappears (generally) again, int nthing (10) (final state). This usually hlds true fr all classes, meaning in mst classes yu will find an initial state (1) and a final state (10).Over the curse f its life, an plane (please nte: we are here talking abut the bject plane and nt abut a real airplane) can take up three states: rdered (3),in maintenance (5), and ready fr use (7) The event «M» plane rdered, leads t the ccurrence, that frm nwhere (1) a new plane bject is created in the IT system (birth). Immediately after it has been created it is in the state rdered (3). If the event «M» plane delivered (4) ccurs, and the plane is the state rdered (3), it changes t the state in maintenance (5). If the plane is in any ther state than rdered, nthing happens. Thrugh the events «M» plane available (6) and «M» plane nt available (8), the plane changes any number f times between the states in maintenance (5) and ready fr use (7). At the end f its life, the airplane bject disappears thrugh the event «M» plane withdrawn (9) int nthing (10), meaning it will be deleted (death). Figure 4.49 shws mre elements that can ccur in statechart diagrams:
Figure 4.49 Statechart diagram with internal transitins and guard cnditins. In additin t the transitins we have already explained, there are als internal transitins. The event«m» assign plane (1), which ccurs when the plane is assigned t a flight, initiates n transitin t anther state. Rather, the plane remains in the state ready fr use (2). This cnstitutes an internal transitin; the plane bject is in the same state ready fr use (2) befre and after the event. A guard cnditin allws acceptance r rejectin f an event depending n a cnditin. If in the statescheduled fr maintenance (3) the event «M» cmplete flight (4) ccurs, the respnse f the bject depends n the guard cnditin stated in brackets. If the cnditin [mre flights] (5) is true (meaning there are mre flights assigned t the plane) an internal transitin takes place. The plane remains in the state scheduled fr maintenance (3). Hwever, if the cnditin [n mre flights] is true (meaning n ther flights are assigned t the plane) a transitin t the state in maintenance (7) takes place. Figure 4.50 Statechart diagram
Actins indicate hw an bject respnds t a mutatin event. Figure 4.50 shws several types f actins. An actin always fllws the slash (1) after the event. The actins CREATE (2) and SET registratin number = (input) (4) fllw the mutatin event «M» plane rdered. CREATE indicates that a new bject is created; SET registratin number = (input) indicates that a value, which the user entered in the use case, is assigned t the attribute registratin number. Individual actins are divided by a semicln (;) (3). In additin t these semi-frmal actins, such as CREATE and SET (seecnstructing Statechart Diagrams), actins can als be described in free text. Fllwing the mutatin event «M» assign plane is the actin create relatinship t flight (5), which indicates that a relatinship t a flight bject is created. If n actin is stated fr an event (6), this can either mean that the actin has nt yet been specified, r that the bject merely transitins int anther state. Gaining a deeper understanding f ur case study, yu will ntice that the statechart diagram in Figure 4.50 will have t be amended with further states and events. A statechart diagram that dcuments all pssible paths f an bject cannt simply be read in a sequential manner. Hwever, it helps the reader t answer several typical questins: What happens t the bject if a certain event ccurs? Since the answer t this questin in each case depends n the current state f the bject, the questin shuld really be: Hw des an bject in a certain state respnd t a certain event? Which events are relevant fr the bject? Hw, meaning thrugh which events, can a certain state be left? Hw, meaning thugh which events, can a certain state be achieved? Let's try t answer sme f these questins by lking at the statechart diagram f the class plane in Figure 4.51:
Figure 4.51 Selective reading f a statechart diagram Hw des a plane bject in the state ready fr use (1) react t the event «M» assign plane? In rder t answer this questin, we have t check first if the event «M» assign plane even exists in the stateready fr use (1). The event is allwed if a transitin (an arrw) t anther state exists that is labeled with the event name, r if an internal transitin exists (an entry in the lwer part f the state symbl). In ur example, a transitin t anther state des nt exist but an internal transitin des. This means: A plane bject in the state ready fr use (1) accepts the event «M» assign plane and remains in the state ready fr use (1). Hw des a plane bject in the state scheduled fr maintenance (2) react t the event «M» cmplete flight? In rder t answer this questin we check first if the event «M» cmplete flight even exists in the state scheduled fr maintenance (2). In ur example, we have a transitin t anther state, as well as an internal transitin. Since nly ne transitin is pssible, (the plane bject is suppsed t be in exactly ne definite state and nt tw) we need criteria in rder t determine which transitin is suppsed t take place. Here, we have the help f the guard cnditins [mre flights] (3) and[nmre flights] (4). We have t check if there are mre flights assigned t the plane. In ur case we assume that n mre flights are assigned t the plane. This means: A plane bject in the statescheduled fr maintenance (2) accepts the event «M» cmplete flight and transitins t the state in maintenance (5), since n mre flights are assigned t it. Hw des a plane bject in the state scheduled fr maintenance (2) react t the event «M» assign flight? In rder t answer this questin, we check first if the event «M» assign flight even exists in the state scheduled fr maintenance (2). In ur example, neither a transitin t anther state nr an internal transitin
exists. This means: A plane bject in the state scheduled fr maintenance (2) des nt accept the event «M» assign plane. (The IT system shuld infrm the user abut the reasn why assigning the plane did nt wrk.) Which events are relevant fr a plane bject? The answer is: All events that are cntained in the statechart diagram f the class plane, meaning all events that are accepted in at least ne state. All ther events are nt relevant fr the plane bject. This means: The nly events relevant fr a plane bject are «M» plane rdered, «M» plane delivered, «M» plane available, «M» plane nt available,«m» assign plane, «M» cmplete flight, «M» scheduling plane fr maintenance, and «M» plane withdrawn. Thrugh which event can the plane bject leave the state in maintenance (5)? In rder t answer this questin, we search all transitins (arrws) that g frm the state in maintenance (5) t anther state. Our example has tw such transitins. This means: A plane bject in the state in maintenance(5) can nly leave this state thrugh the event «M» plane available, r «M» plane withdrawn. Thrugh which events des a plane bject reach the state ready fr use (1)? In rder t answer this questin, we search fr all transitins (arrws) that lead t the state ready fr use (1). Our example has exactly ne such transitin. This means: A plane bject can nly reach the state ready fr use(1) thugh the event «M» plane available (namely, frm the state in maintenance (2)). The questins discussed have already shwn that in statechart diagrams, what is nt written is just as imprtant as what is written. Events that d nt exist in a certain state are nt accepted if the bject is in this state. This means that an event that was nt accepted cannt be successfully executed within the IT system. An apprpriate errr message has t be generated. Events that d nt exist in any state are always ignred. The fllwing statements can be read frm the statechart diagram fr the plane bject: The questins discussed have already shwn that in statechart diagrams, what is nt written is just as imprtant as what is written. Events that d nt exist in a certain state are nt accepted if the bject is in this state. This means that an event that was nt accepted cannt be successfully executed within the IT system. An apprpriate errr message has t be generated. Events that d nt exist in any state are always ignred. The fllwing statements can be read frm the statechart diagram fr the plane bject: If a plane is delivered it is never directly in the state ready fr use, it is always first in the state in maintenance. A plane ready fr use cannt be withdrawn. If this is attempted anyway, the mutatin event fails with an apprpriate errr message.