Object Oriented Development with UML 11 12 18
Object Oriented Development with UML 11 -12, 18 -19 November 2006 At Sipa Chiangmai State and Activity Diagrams โดย รศ. รงสต ศ ร รงษ อ. สายณห
What is a State Diagram? n n n State Event Guard n n Transition Action Event State Name state. Var : type = value entry/ entry activity do/ activity exit/ exit activity event(args) [guard condition] ^target. send. Event(args) / operation(args) Transition Other State Name
Guard condition n n guard-condition เปน boolean expression ทใชสำหรบ triggers event ทกอใหเกด transition อาจใชสำหรบการทดสอบสถานะภายในของ u birthdate < current_date Fit evaluates to TRUE/ FALSE event name guard ออปเจคได เชน } event)arguments( ]condition[ /operation(arguments( action trigger
Event-Transition Notation เงอนไขกอนท ชอของ event ททำใหเกด State 1 do/activity 1 n event(args) [guard condition] ^target. send. Event(args) / operation(args) transition จะเกดขน transition การทำงานของ action เมอเกด event [condition] /action event State 2. . . transition ���������� state ใหม ��������� action state ใหม ������� state ������� transition ����������� event
Activity n n n เปนกจกรรมการทำงานทเกยวกบ state ทใชเวลาชวงหนง ๆ จนกระทงเสรจสน Activity จะมผลทำใหเกด transition ออกไป ไมวาจะทำจนเสรจสนหรอถกขดจงหวะโดย event รปแบบตาง ๆ ของ state behavior: u event name [guard condition]/ action State Name u do / Activity state. Var : type = value u entry / action entry/ entry action u exit / action do/ activity exit/ exit action
Elevator : State Diagram 1 n state diagram สำหรบ (elevator( ลฟท go up Moving Up arrived go down Idle Moving Down arrived -timeout go up On First Floor arrived Moving to First Floor • ������������ • ������������ time-out event
Elevator : State Diagram 2 n การนำเสนอ state diagram ทใชแสดงการ On first floor go up arrieved operations Moving Up do: moving to floor arrived Moving to first go up(floor( Idle Moving Down arrieved timer = 0 do: moving to floor do: increase timer go down(floor( ]timer = time out[
Elevator : State Diagram 3 n การนำเสนอ state diagram เพอแสดง event/actions go up( floor( Moving Up do: moving to floor arrived Idle entry: timer = 0 do: increase timer arrived out[ ]timer =time - go up( floor( On First Floor go down( floor( arrived Moving to First Floor Moving Down do: moving to floor
State Diagram : Order [ not all items checked ] / get next item / get first item Checking do: check item Item received[ some items not in stock ] [ All items checked && some items not in stock ] Waiting Item received[ all items available ] [ All items checked && all items available ] cancelled Dispatching do: initiate delivery Delivered cancelled Cancelled
Composite State. Chart Diagrams n n nested statechart diagram เปนไดอาแกรมทมมากกวา 1 state region u ออปเจคจะมเพยง 1 state ใน 1 ของ state diagrams Fใชสำหรบ State ทเปนเงอนไขแบบ or-condition บนทก ๆ statechart diagrams u ใช abstract/generalize states ในรปของ state เดยว concurrent statechart diagram u ออปเจคจะมเพยง 1 state ใน 1 ของ statechart diagrams Fใชสำหรบ state ทเปนเงอนไขแบบ and-condition บนทก ๆ statechart diagrams u ใชสำหรบแสดงการทำงานแบบ multi-threading
Superstate / Substates Active [ not all items checked ] / get next item / get first item Item received[ some items not in stock ] [ All items checked && some items not in stock ] Checking Waiting do: check item [ All items checked && all items available ] Dispatching do: initiate delivery cancelled Cancelled Item received[ all items available ] Delivered
Concurrency Among State. Chart Diagrams Ignition guard references Transmission statechart diagram Off [Transmission in Neutral] turn key to start Starting release key On turn key off Transmission select R Neutral Reverse select N select F select N Forward stop First upshift downshift Second upshift downshift Third
Class definition package Traveling; public class Car { private Location current. Location; private java. sql. Date built. Date; } public class Location { private java. lang. String city; }
Adding methods public class Car { private Location current. Location; private java. util. Calendar built. Date; public void start ( ) { return; } public void stop ( ) { return; } public void goto. Location (Location new. Loc ) { current. Location = new. Loc; } Missing: accessing methods }
State transitions public class Car { private Location current. Location; private java. util. Calendar built. Date; private String state; private boolean gas. Available; stopped public void start ( ) { if (gas. Available) {state = "started"; }; return; } public void stop ( ) { state = "stopped"; return; start[ gas available ] } public void goto. Location (Location new. Loc ) { current. Location = new. Loc; } started } stop
The example we will use n n Class Course. Offering u กำหนดคาเรมตน students. No = 0 u จำนวนสงสด student. No = 10 u จำนวนตำสด =3 u เกดการ cancelled เมอ Fจำนวนนกศกษาตำกวา min u มการ closed เมอนกศกษา = max Events u initialize u add student u remove student
State Transition (Reflexive & Arguments) n n Reflexive state transition เปน transition ทเกดขนเมอ successor state เปน originating state event จะถกนำเสนอรวมกบจำนวนขอมลในรปของ argument
Standard Events for a State n Standard events ทอาจเกยวของกบแตละ state u Entry - ระบ actions เมอเขาส state u Exit - ระบ actions เมอออกจาก state u Do - ระบ activities ทเกดขนใน Statestate Name state. Var : type = value entry/ entry action do/ activity exit/ exit action
State Diagram for the Course. Offering Class
Detailed Course. Offering class add. Student Initialize do: Initialize course object Unassigned do: Assign lecturer to course add. Student/ num. Students = 0 cancel. Course Open entry: Register a student cancel. Course Canceled do: Send cancellation notices registration closed[ num. Students < 3 ] registration closed[ num. Students > = 3 ] [ num. Students = 10 ] cancel. Course Closed do: Report course is full Registration. Complete do: Generate class roster
How Do State Diagrams Map to the Rest of the Model? n n n Events สามารถ map เปน operations Methods จะถก updated พรอมกบขอมลเฉพาะของ state States ถกนำเสนอผาน attributes u ใชสำหรบเปน input ในขนตอนการกำหนดคา Attributes Open [num. Students = 10] Closed Course. Offering add. Student /- num. Students + add. Student()
Phone Call example: The caller picks up the phone. A dial tones is heard on the phone line. The caller dials 7 digits. A dialling sound is heard on the phone line. After the seventh digit, the phone rings. The callee answers the phone.
Analysis: UML Activity Diagram Define use cases Define participating objects Define entity objects Define boundary objects Define control objects Define interactions Define nontrivial behavior Define attributes Consolidate model Review model Define associations
Activity Diagram Activity diagrams ประกอบไปดวย : § Activity states และ action states § Transitions § Objects Initial state Select site Action state Commission architect Develop plan Sequential branch Bid plan concurrent fork [not accepted] [else] Do trade work() Do site work final state Activity state with submachine concurrent join Finish construction object flow : Certificate. Of. Occupancy [completed]
Order Processing Domain Model Order. Line * date. Received is. Prepaid number price quantity price is. Satisfied dispatch() close() * Customer Places 1 name address credit. Rating()
Order Processing Activity Diagram Receive Order for each line * item on order Check Line Item [failed] Authorize Payment [succeeded] Cancel Order [in stock] Assign to Order [stock assigned to all line items and payment authorized] Dispatch Order [need to reorder] Reorder Item
Activity Diagram for Receiving an Order Receive order * for each line item on order [failed] Cancel Order Authorise Payment [succeede d] Check line item [in stock] Assign to Order [need to reorder] [stock assigned to all line items and payment authorised] Dispatch Order Reorder item
Order Processing Finance Receive order Receive Supply * for each line item on order Authorise Payment Check line item [failed] [succeeded] Cancel Order [in stock] Assign to Order [need to reorder] [stock assigned to all line items and payment authorised] Dispatch Order Stock Manager Choose outstanding order items * for each chosen order item Assign goods to order Reorder item [all outstanding order items filled] With Swimlanes Add remainder to stock
Class Diagram : Specification Level
Sequence Diagram Level 2: Login
Implementation : Login Class Diagram
Login Activity Diagram
Sequence Diagram Level 2: Register
Implementation : Login Class Diagram
Register Activity Diagram
- Slides: 63