7.2 TransitionsGiven the states of an element, how are they related to one another? Transitions address this question. As discussed in Chapter 2, transitions between states occur as follows:
When an event occurs, the transition is said to fire. In the UML, a transition is shown as a solid line from a source state to a target state labeled with the event followed by a forward slash followed by the action, where the event and action are optional and the forward slash is used only if an action is shown. The next few sections discuss events and actions.
7.2.1 EventsAn event is an occurrence, including the reception of a request. For example, the project management system may respond to the following events:
In the UML, an event is described using the following UML syntax: event_name (parameter_list) [guard] in which:
The UML also allows you to show an event using pseudocode or another language. For example, you can use the syntax of Java, C++, C#, or some other programming language. Following is an example of an event defined using the syntax just shown. The event informs the project management system to start up: Startup If this event requires the user's identification, you can update the event to the following: Startup (UserID) If the project management system responds to this event only if it can start up, perhaps if enough memory is available, you can update the transition to the following: Startup (UserID) [Enough memory is available] Figure 7-3 shows this transition occurring between the Inactive state, which indicates that the project management system is not available for processing, and the Active state, which indicates that the project management system is available for processing. Figure 7-3. Transitions with eventsFigure 7-3 also shows a transition originating from the initial state labeled with the event that creates an instance of the project management system and a transition to the final state labeled with the event that destroys an instance of the project management system. Finally, Figure 7-3 shows the various events associated with the project management system, including the Startup, Shutdown, Sever Error, and Reset events. 7.2.2 ActionsAn action represents processing. For example, the project management system may respond to events with the following actions:
In the UML, an action is described using the following UML syntax: return_variable := target_element.action_name (argument_list) in which:
The UML also allows you to show an action using pseudocode or another language. For example, you can use the syntax of Java, C++, C#, or some other programming language. Continuing with the example from the previous section, the following action passes the user's time zone to the operating system (OS) using the getDateAndTime operation: OS.getDateAndTime (TimeZone) If this action returns some output data (the current date and time), you can update the action to the following: DT := OS.getDateAndTime (TimeZone) Figure 7-4 updates Figure 7-3 and shows the events and actions for the transitions between the Inactive and Active states. You can see the logging of a message using the LogMessage action when the system is shut down, and you can see that the Startup event triggers the retrieval of the date and time using the getDateAndTime action of the OS object, which represents the operating system. Figure 7-4. Transition with events and actions |