1 / 31

Lecture Outline

วิชาวิเคราะห์และออกแบบระบบเชิงวัตถุ Lec09 :: Behavioral Modeling with UML Behavioral Diagrams Interaction Diagrams State Diagrams Activity Diagram Last Updated :: 17/04/2551 Mr. Nattapong Songneam xnattapong@hotmail.com http://www.siam2dev.com. Lecture Outline. Behavioral Diagrams

nishi
Download Presentation

Lecture Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. วิชาวิเคราะห์และออกแบบระบบเชิงวัตถุLec09 :: Behavioral Modeling with UMLBehavioral Diagrams Interaction DiagramsState DiagramsActivity Diagram Last Updated :: 17/04/2551Mr. Nattapong Songneamxnattapong@hotmail.comhttp://www.siam2dev.com

  2. Lecture Outline • Behavioral Diagrams • State-Transition Diagram • Activity Diagram

  3. UML has 9 kinds of diagrams • Class Diagram • Object Diagram • Component Diagram • Deployment Diagram • Use Case Diagram • Sequence Diagram • Collaboration Diagram • StateTransition Diagram • Activity Diagram Structural Diagrams Behavioral Diagrams

  4. Behavioral Diagrams • Behavioral Diagrams เป็นโครงสร้างแบบ dynamic • 4 diagrams ได้แก่ • Sequence Diagram • Collaboration Diagram • State-transition Diagram • Activity Diagram Interaction Diagrams

  5. Add student[ count < 10 ] Add Student / Set count = 0 Initialization Open do: Initialize course entry: Register student exit: Increment count Cancel Cancel [ count = 10 ] Canceled do: Notify registered students Closed Cancel do: Finalize course A State-Transition Diagram

  6. Ordinary Example Show MessageBox “Printing” on Screen Create postscript file Send postscript file to printer Remove MessageBox sampler Swimlane Example displayer An Activity Diagram

  7. State Diagram

  8. State diagram • แสดงพฤติกรรมของวัตถุใดๆ วัตถุหนึ่งที่สร้างขึ้นจากคลาส • แสดงสถานะ (states) ทั้งหมดที่เป็นไปได้ของวัตถุ • แสดงการเปลี่ยนแปลงสถานะของวัตถุ ที่เป็นผลจาก message ที่วัตถุนั้นได้รับ • ชื่ออื่นๆ ของ State Diagram ได้แก่ • State transition diagram • Harel diagram (statecharts)

  9. Account balance : Float Object states • สถานะ (State) = ชุดของค่าที่ บ่งบอกถึง วัตถุ (รวมทั้ง condition และ situation ของวัตถุ) ที่เวลาใดเวลาหนึ่ง • สถานะถูกกำหนดโดยค่าของ attribute ในวัตถุ overdrafted states ok

  10. State changes (1) • สถานะอาจเปลี่ยนแปลง เมื่อมีเหตุการณ์ (event) เกิดขึ้นกับวัตถุ • State transition • หมายถึงความสัมพันธ์ที่ระบุการเปลี่ยนแปลงของสถานะ overdrafted withdraw(sum) deposit(sum) ok

  11. deposit overdrafted withdraw deposit withdraw ok State changes (2) • เหตุการณ์ (Events) • หมายถึง Message หรือ signal ที่วัตถุได้รับ • Events อาจจะทำให้สถานะของวัตถุเปลี่ยนแปลง หรือไม่ก็ได้ • Self-transition

  12. State name state variable(s) entry / entry-action do/ activity-A event1(a:T)[exp]: action1 … eventn(a:T)[exp]: actionn condition /conditiont-action exit / exit-action State diagram notation (1) • entry / entry-action • เมื่อเข้ามายัง State นี้ให้ทำ entry-action • do / activity-action • หลังจากเข้ามายัง State นี้แล้ว หากไม่มีเงื่อนไขอื่นใดให้ทำ activity-action • exit / exit-action • ขณะที่จะออกจาก State นี้ ให้ทำ activity-action • conditon / condition-action • ขณะที่อยู่ภายใน State นี้ ให้ทำ condition-action ตามเงื่อนไขที่กำหนด

  13. Event(arguments)[condition]/action State-A State-B State diagram notation (2) • Event • หมายถึง เหตุการณ์ที่เกิดขึ้นใน time และ space • ก่อให้เกิด (trigger) การเปลี่ยนสถานะ (transition) • อาจเป็น signals, calls, ช่วงเวลา หรือ การเปลี่ยนสถานะ • Condition • Transition อาจเกิดขึ้นเมื่อ condition เป็นจริงเท่านั้น • Action • หมายถึง กระบวนการที่เกิดขึ้นโดยอย่างรวดเร็ว โดยไม่ถูกขัดจังหวะ

  14. State diagram notation (3) Event(attribute) Initial state State-B • Start state • ไม่มี event triggers • อาจมี branch conditions • อาจเปลี่ยนสถานะจาก start states • End state • สิ้นสุด state machine StartState End State

  15. Created Paid Destroyed Unpaid Paid Example : State transitions for an invoice

  16. Item received[someitems not in stock ] [ not all items checked ] / get next item [ All items checked && some items not in stock] / get first item Checking Waiting do : check item [ All items checked && all items availables ] Item received[ all items available] Dispatching Delivered Delivered do : initiate delivery Example : State transitions for an order

  17. [ 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 items available ] cancelled [ All items checked && all items available ] cancelled Dispatching cancelled do: initiate delivery Cancelled Delivered Delivered Transitions to “cancelled”

  18. State diagram notation (4) Superstate Event A State-A State-B State-B Event C Event B • Composite state: • Sequential substates

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

  20. Exercises • ให้สร้าง State diagram สำหรับ • an elevator • a soccer game • an ATM • a mobile phone • …

  21. Activity Diagram

  22. Activity diagram • ใช้สำหรับอธิบาย • กระแสการไหลของการทำงาน (workflow) • การประมวลผลแบบขนาน (parallel processing) • Activities • conceptual: task to be done • specification/implementation: method of a class • Similar to Petri nets

  23. Structure of activity diagrams • Synchronization bar: • outbound triggers: activities can be carried out in parallel (any order) • default: outbound triggers occur when all incoming triggers occurred (i.e. all predecessors finished) • Activity diagram shows partial order of activities Concurrent fork Activity Synchronization Bar Activity Activity [synchronization condition] Concurrent join Activity

  24. Example of activity diagrams • The Coffee Pot

  25. Activity diagram Find coffee Put coffee Add water in filter to reservoir Put filter in machine Turn on machine

  26. Conditions in activity diagrams Find coffee Sequential branch unguarded transition Put coffee Check water in filter in reservoir [not enough water] Put water in the reservoir Put filter in machine [else] [filter with coffee in machine and reservoir contains water] Turn on machine

  27. Activity Branch Guard expression Structure of activity diagrams [condition 1] Activity [condition 2] Activity Activity • Strictly UML: • forks  joins • branch  merge • No synchronization condition [synchronization condition] Activity

  28. Customer Sales Warehouse Swimlanes Request product • Identify responsibilities • Example:Modeling workflows for business units Process order Pull material Ship order

  29. Customer Sales Warehouse Request product Process Order Pull Material Continue Work Ship Order Recieve Order Bill Customer Pay Bill Close Order

  30. Warehouse Customer Sales Request product Process Order Pull Material Continue Work o:Order [in progress] Ship Order o:Order [filled] Recieve Order Bill Customer b:Bill [unpaid] Pay Bill b:Bill [paid] Close Order

  31. Summary • Software Modeling • Require and Domain Analysis Model • Design Model • Brief Overview of Unified Modeling Language (UML) • Use Case Model

More Related