Presentation is loading. Please wait.

Presentation is loading. Please wait.

State Machine Model.

Similar presentations


Presentation on theme: "State Machine Model."— Presentation transcript:

1 State Machine Model

2 State Machine View Describes the dynamic behavior of objects over time
Each object is treated in isolation This view describes events and operations that manipulate the object under discussion The state view of the entire system is described by a collection of state diagrams, one diagram corresponding to each class in the system Objects object C-S 446/546

3 Main components of a state diagram
A collection of states of the object under consideration A collection of actions while entering a state, exiting a state or within a state A collection of transitions between states A collection of events that trigger transitions A collection of conditions (optional) that might constrain firing of transitions States Actions Transitions Events conditions C-S 446/546

4 State diagram – basic syntax
event (EventParams) [guard] / action (ActionParams) initial State name actions entry/ … exit/ … do/ event (params) event (Eparams) / action (Aparams) actions final Unnamed states C-S 446/546

5 State diagram - semantics
There must be exactly one initial state and one or more final states Some state diagrams do not show the final states; in this case, there is an implicit final state when the program terminates A transition between states is represented by the event that triggers the transition Transitions may have guards or conditions under which the transitions fire One One or more C-S 446/546

6 State diagram – semantics (continued)
A state may optionally have a label Every state may have An entry action – executed as soon as the state is entered An exit action – executed just before leaving the state A “do” action – executed while the object is in this state; it may be ongoing action until the object leaves the state C-S 446/546

7 State diagram for ATM Account Class
Check balance (act) Deposit (amount) Check balance (act) Deposit (amount) Transfer (act, amount) [balance > amount] Normal Initial Transfer (act, amount) [balance=amount] Withdraw (amount) [balance > amount] close Withdraw (amount) [balance = amount] State diagram for ATM Account Class Actions associated with transitions are not shown in this diagram C-S 446/546

8 State – a formal definition
A state is a condition in the life of an object during which the object performs an action or waits for some event A state is represented by the collection of attributes and their corresponding values An object after being created must be in at one particular state at any instant Unless otherwise mentioned, an object remains in a state for a finite time UML allows modeling of transient states (states that exist only for a very short and insignificant duration) C-S 446/546

9 State – a formal definition (continued)
A state (directly or indirectly) includes links (instances of associations) connected with the object at that instant A state may be decomposed into concurrent sub-states (AND relationship) A state may be composed using mutually exclusive disjoint sub-states (OR relationship) C-S 446/546

10 Event – a formal definition
A noteworthy occurrence UML manual version 1.5 Something that happens within the system or interacting with the system at an instant Something that has a significant impact on the system Examples sending a signal or data receiving a signal or data making a request for execution a Boolean condition becoming true a timeout condition becoming true C-S 446/546

11 Four types of events in UML
Signal event occurs when an object sends a signal to another object Call event occurs when a method or operation in an object is invoked Change event occurs when a Boolean condition is changed Time event occurs when a time limit has reached Kindergarten-first grade-second grade Job applicaion, interview C-S 446/546

12 Representation of events
Events are represented by unique labels in the diagram Generally, the transitions that are fired by the occurrence of the event are also represented by the same label Change event labels are preceded by the keyword “when” Time event labels are preceded by the keyword “after” C-S 446/546

13 Generating an Event An event is generated by the runtime system
Asking for inputs Producing outputs Execution of a method Transfer control of execution from one object to another (sending messages or receiving messages) Abnormal termination Error handling, exceptions C-S 446/546

14 Temporal properties of Events
An event is considered to be instantaneous Occurrence of an event causes negligible time This time is not included in the modeling Events may have precedence relationships among them In ATM system, “opening an account” precedes “depositing into account” In course registration system, “enrolling a student in a course” can occur only after “checking the prerequisites completed by the student” C-S 446/546

15 Transition Represents the change of states of an object
switch from “Empty balance” to “Positive balance” A transition is an abstraction of an operation The above transition is an abstraction of deposit operation A transition has finite and significant duration Observable time taken to complete deposit operation C-S 446/546

16 Transition (continued)
A transition may have parameters A transition corresponding to the deposit operation will have the “amount” as a parameter A transition is triggered/invoked/fired by the occurrence of an event The transition corresponding to deposit will occur by the event “request for deposit” The transition from “Positive balance” to “Empty balance” occurs by the completion of the operation “withdrawal” C-S 446/546

17 Transition (continued)
A transition may have a guard/condition The transition corresponding to the withdrawal operation will occur only if the balance is greater than or equal to the amount to be withdrawn The condition associated with a transition is always the precondition for the transition and hence must be checked before the transition occurs An event may cause several transitions to fire The event that triggers the transition to move to “Empty balance” state after withdrawal may also cause a message to be sent to the account holder and at the same time may also cause a note to be recorded in the account log C-S 446/546

18 Example 1 – State of a “Student”
name : String id : Integer courses : set of CourseID name = “John” id = courses = {CS546, CS742} Class definition The state of a student object : Student name = “John” id = courses = {CS546, CS742, CS551} Another state of the student object C-S 446/546

19 Example 1 – Simplified representation
: Student Student courses = {CS546,CS742} courses : set of CourseID : Student courses = {CS546, CS742, CS551} Indicate only those attributes that define change of state C-S 446/546

20 Example 1 – State diagram for Student class
register [#courses < minRequired] / updateCourses() register[#courses < minRequired] / updateCourses() Initial continuing entry/ initializeCourses() register [#courses >= minRequired] / updateCourses() completed graduated [complete Graduation Requirements] C-S 446/546

21 Exercise 1 The given state diagram for the student class is incomplete. Complete the diagram to include transitions that correspond to withdrawal from a course C-S 446/546

22 Exercise 2 Complete the state diagram for the Account class in ATM, by including additional states and transitions to allow withdrawals below the available balance. C-S 446/546

23 Exercise 3 Draw the state diagram for an object that performs login validation as described in the following example. A login subsystem validates first whether a username is the right format. Second, it checks whether the password is in the right format. Third, it checks whether there is an account corresponding to the username. Finally, it verifies whether the username and password match with the existing account. C-S 446/546

24 Exercise 4 Draw the state diagrams for objects in a simple three-light traffic light control system. C-S 446/546


Download ppt "State Machine Model."

Similar presentations


Ads by Google