Presentation is loading. Please wait.

Presentation is loading. Please wait.

Behavioral diagrams Lecture p4 T120B029 2012 pavasario sem.

Similar presentations


Presentation on theme: "Behavioral diagrams Lecture p4 T120B029 2012 pavasario sem."— Presentation transcript:

1 Behavioral diagrams Lecture p4 T120B029 2012 pavasario sem.

2 2 State diagrams Positioning in development process Basic definitions and symbols Notations Examples Remarks Concurrency Events, signals, exceptions T120B029

3 3 Main processes of the team assignment requirements analysis design process codingtesting Used technique: UML use case diagrams UML activity diagrams Used technique: UML component diagrams, UML class diagrams, UML state diagrams UML sequence diagrams, UML activity diagrams Used languages: Java C++ … requirements document problem description design document T120B029

4 4 Refined design processes of the team assignment requirements analysis design process codingtesting create system architecture specify component interfaces develop component design Used technique: UML class diagrams, UML state diagrams UML sequence diagrams, UML activity diagrams Used technique: UML component diagrams T120B029

5 5 S tate diagrams Shows the behavior of one object of a single class –shows all possible states of this object –shows how the object’s state changes as a result of messages it receives –narrowly focused, fine-grained Other names –State transition diagram –Harel diagram (statecharts) T120B029

6 6 Object states State = set of values that describe an object (its condition/situation) at a specific moment in time State is determined based on the attribute values overdrafted ok Account balance : Float states T120B029

7 7 State changes (1) States may be changed when an event occurs State transition: relationship indicating a state change –atomic (i.e. non- interruptible) overdrafted ok deposit(sum)withdraw(sum) T120B029

8 8 State changes (2) Events: Messages or signals received Events may or may not change the state –Self-transition overdrafted ok deposit withdraw deposit withdraw T120B029

9 9 State diagram notation: for one state Activity: Can take longer and can be interrupted Action: Occurs quickly –“quickly” = non-interruptible –entry: an action that is performed on entry to the state –exit: an action performed on exiting the state do: an ongoing activity performed while in the state (example: display window) on: an action performed as a result of a specific event –Different from self-transition State name entry / entry-action exit / exit-action do / activity-A event 1 (a:T)[exp]: action 1 state variable(s) event n (a:T)[exp]: action n … T120B029

10 10 State-A State-B Event(arguments)[condition]/action State diagram notation: from one state to another Event: significant occurrence that has a location in time and space –triggers the transition –signals, calls, passing of time, change in state Guard condition: Transition only occurs when guard evaluates to true Guards of transition exiting one state are mutually exclusive Action: Processes considered to occur quickly and are not interruptible Note: Each part can be omitted! T120B029

11 11 State diagram notation: special states Start state –No event triggers allowed –branch conditions allowed –may not remain in start state End state –Top level end state terminates a state machine Initial state State-B Event(attribute) Start State End State T120B029

12 12 Let us look at an example of Statechart Diagrams : Order Management T120B029

13 13 State transitions for an order Checking do: check item Dispatching do: initiate delivery Waiting Delivered / get first item Item received [ some items not in stock ] Item received[ all items available ] Delivered [ All items checked && some items not in stock ] [ All items checked && all items available ] [ not all items checked ] / get next item Event Guard Action T120B029

14 14 Problem: Cancel the order Want to be able to cancel an order at any time Solutions –Transitions from every state to state “cancelled” –Superstate and single transition T120B029

15 15 Transitions to “cancelled” Dispatching do: initiate delivery Waiting Delivered Item received[ some items not in stock ] Item received[ all items available ] Delivered Cancelled Checking do: check item [ not all items checked ] / get next item / get first item [ All items checked && some items not in stock ] [ All items checked && all items available ] cancelled T120B029

16 16 State diagram notation: structuring diagrams (1) Superstate State-AState-BState-AState-B Event A Event B Event C Composite state: Sequential substates T120B029

17 17 Superstate / Substates Dispatching do: initiate delivery Waiting Delivered Item received[ some items not in stock ] Item received[ all items available ] Delivered Cancelled Checking do: check item [ not all items checked ] / get next item / get first item [ All items checked && some items not in stock ] [ All items checked && all items available ] Active cancelled T120B029

18 18 State diagram notation: structuring diagrams (2) Superstate State-AState-BState-AState-B Event A Event B Event C H History state Start with the last substate that was active prior to leaving the composite state T120B029

19 19 Another example: Icehockey with superstate Normal playing break Fighting end of game shootout penalty face off time is uo [win ] time is up [tie] T120B029

20 20 Remarks (1) Statechart diagrams do not have to refer to classes or objects, they can also refer to subsystems etc… However, often describing classes is the most widely use of statechart diagrams... T120B029

21 21 Remarks (2) Only one initial state may occur (directly) within a composite state End state represents completion of a composite End state triggers transition with composite as source T120B029

22 22 Orthogonal components and concurrency Unrelated components of objects combinatorial number of states Example: Car states –engine (started, stopped) –doors (open, closed) What happens when we add one component? –seat belt (fastened, open) 4 car states: started_open started_closed stopped_open stopped_closed 8 car states: started_open_open started_open_fastened started_closed_open started_closed_fastened stopped_open_open stopped_open_fastened stopped_closed_open stopped_closed_fastened T120B029

23 23 Example: Payment authorization in class Order Authorizing do: check payment Authorized Delivered Rejected [ payment ok ] [ payment not ok ] 2 parallel processes: - authorization - order handling T120B029

24 24 Concurrent state diagram for the class Order Checking Waiting Dispatching Authorizing Authorized Checking Waiting Dispatching Authorizing Authorized Cancelled Delivered Rejected T120B029

25 25 Rules of thumb Not every class needs a state diagram Often: State diagram not very complex State diagrams are often used for UI and control objects Not too many concurrent sets of behavior occurring in a single object (in that case: split into separate objects) T120B029

26 26 Proposed Exercises Define a statechart diagram for –a hockey game –an elevator –a soccer game –… T120B029


Download ppt "Behavioral diagrams Lecture p4 T120B029 2012 pavasario sem."

Similar presentations


Ads by Google