Homework 4 - Statechart Diagrams
The front door of Brahegatan 4 has a combined code lock and telephone, Figure 1, that works in the following way:
To unlock the door, press 'C' and enter the correct 4-key code. The door is unlocked for a few seconds, during which pressed keys are ignored. If the code is not entered within a certain time the lock is reseted.
To phone an apartment, enter the correct 4-key apartment number and then press 'C'. The phonecall ends when either the lock phone user press 'R' or the apartment user ends the call. During a phonecall, pressed keys are also ignored. If the number is not entered within a certain time the lock is reseted.
An incorrect code or a nonexisting apartment number is ignored.
Figure 1 The code lock and telephone
The usage requirements is specified in the use cases in Figure 2 below, and the use case diagram in Figure 3 (the code lock and telephone is named LP).
Figure 2 Use cases
Figure 3 Use case diagram
Assignment
Define a class to represent the lock (you do not have to define any class diagram). One class is all that is needed. Define public operations (you do not have to model parameters and types). Since the class has a rather complicated internal behavior with different states we will describe its behavior with a statechart diagram.
Construct a statechart diagram, connected to the class, that describes the behaviour of the lock and phone. Each state should be named, and contain a short description (written in the documentation part of its specification). The transitions should be named according to the events they represent, and marked with appropriate actions and guards.
Reporting the assignments (deadline 2002-02-19, 12.00)
Send the file to your lab assistant, following the naming conventions described on the main lab homepage.
Statechart Diagrams in Rational Rose
- Create a class
Right-click on "logic view", and chose "new > class"
- Create an operation for a class
Right-click on the class, and chose "new > operation"
- Create a statechart diagram for a class
Right-click the class in the model browser (the left window containing the tree structure of the model), and chose "new > Statechart Diagram". Or right-click the class in the class diagram, and chose "Sub Diagrams > New Statechart Diagram"
- Set/change specification of a state or transition
Double-click, or right-click and chose "open specification", in the diagram or in the model browser.
- Delete state
A state is still kept in the model if it is removed from a diagram. To completely delete a state, select it in the model browser and press "delete", or right-click and chose "delete".
- Delete a transition
Transitions can not be seen in the model browser. Instead, they are a part of the specifications of the states they connect. Thus, to completely delete a transition, open the specification of one of the states. Choose "transitions", right-click the event column of the transition you want to delete, and choose "delete".
Hints and FAQ
- Event The event is what causes a transaction. A transition, marked with the event E, from the state S to the state T means: "If the system is in state S and E happens, the system should change to state T".
- Action An action describes what should be performed by the system when the transition is made. Thus, if we put an action A on the transition described above, it would mean: "When the system changes from state S to state T (because of E), it should perform A".
- Guard A guard should not describe what must be true in order for an event to happen. The guard simply puts an restriction on when the system is allowed to make the transition. Adding a guard G to our example, it would mean: "If the system is in state S, E happens and G is true, it should change to state T (and perform A)". The most common way to use guards is more than one transition from a state is marked with the same event (like PIN rejected in the example from the lesson.
- 2002-02-12 Some examples of statechart diagrams can be found here.
- 2002-02-12 A common mistake is to remove stuff from a diagram when they should have been removed from the model altogether. Before handing in the solution, check that the model does not contain any extra classes, states, transitions or diagrams.