260 likes | 375 Views
Behavioral diagrams Lecture p4 T120B029 200 4 pavasario sem. State diagrams. Positioning in development process Basic definitions and symbols Notations Examples Remarks Concurrency Events, signals, exceptions. T120B029. Main processes of the team assignment. requirements analysis.
E N D
Behavioral diagrams Lecture p4T120B0292004 pavasario sem.
State diagrams • Positioning in development process • Basic definitions and symbols • Notations • Examples • Remarks • Concurrency • Events, signals, exceptions T120B029
Main processes of the team assignment requirements analysis design process coding testing design document problem description requirements document 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++ … T120B029
design process coding testing requirements analysis create system architecture specify component interfaces develop component design Used technique: UML component diagrams Used technique: UML class diagrams, UML state diagrams UML sequence diagrams, UML activity diagrams Refined design processes of the team assignment T120B029
State 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
Account balance : Float 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 states ok T120B029
overdrafted deposit(sum) withdraw(sum) ok State changes (1) • States may be changed when an event occurs • State transition: relationship indicating a state change • atomic (i.e. non-interruptible) T120B029
deposit overdrafted withdraw withdraw deposit ok State changes (2) • Events: Messages or signals received • Events may or may not change the state • Self-transition T120B029
State name state variable(s) entry / entry-action do/ activity-A event1(a:T)[exp]: action1 … eventn(a:T)[exp]: actionn exit / exit-action 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 T120B029
Event(arguments)[condition]/action State-A State-B 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
State diagram notation:special states Event(attribute) State-B Initial state • 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 End State Start State T120B029
Let us look at anexample of Statechart Diagrams :Order Management T120B029
Event [ not all items checked ] / get next item Item received[ some items not in stock ] Action [ All items checked && some items not in stock ] / get first item Checking Waiting do: check item [ All items checked && Item received[ all items all items available ] available ] Guard Dispatching Delivered Delivered do: initiate delivery State transitions for an order T120B029
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
[ not all items checked ] / get next item Item received[ some items not in stock ] [ All items checked && some items not in stock ] / get first item Checking Waiting do: checkitem Item received[ all [ All items checked && items available ] all items available ] cancelled cancelled Dispatching cancelled do: initiate delivery Cancelled Delivered Delivered Transitions to “cancelled” T120B029
Superstate Event A State-A State-A State-B State-B Event C Event B Composite state: Sequential substates State diagram notation:structuring diagrams (1) T120B029
Active [ not all items checked ] / get next item Item received[ some items not in stock ] [ All items checked && some items not in stock ] / get first item Checking Waiting do: checkitem cancelled Cancelled Item received[ all [ All items checked && items available ] all items available ] Delivered Dispatching Delivered do: initiate delivery Superstate / Substates T120B029
Superstate Event A State-A State-A State-B State-B H Event C Event B State diagram notation:structuring diagrams (2) History state Start with the last substatethat was active prior to leaving the composite state T120B029
Normal time is up [tie] shootout playing Fighting penalty face off time is uo [win ] end of game break Another example:Icehockey with superstate T120B029
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
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
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
Example: Payment authorization in class Order 2 parallel processes: - authorization - order handling Authorizing [ payment not ok ] do: check payment [ payment ok ] Rejected Authorized Delivered T120B029
Cancelled Waiting Waiting Dispatching Dispatching Checking Checking Delivered Authorizing Authorizing Authorized Authorized Rejected Concurrent state diagram for the class Order T120B029
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
Proposed Exercises • Define a statechart diagram for • a hockey game • an elevator • a soccer game • … T120B029