Seq uml

1,923 views

Published on

sequence diagram

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,923
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
88
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Seq uml

  1. 1. Modeling Behavior Interaction Diagrams Activity Diagram State Machine Diagram OOAD 1
  2. 2. Learning Objectives Understand how to represent system logic with interaction diagrams. Understand how to represent system logic with activity diagram. Understand how to represent system logic with state machine diagram.Chapter 8 Appendix © 2008 by Prentice Hall 2
  3. 3. UML Dynamic Modeling• In all systems, events happen dynamically, e.g.: – Objects are created and destroyed – Objects send messages to one another – External events trigger operations on certain objects• Objects have states that would be difficult to capture in a static model OOAD 3
  4. 4. UML Dynamic Modeling (cont.)• Behavior diagrams (dynamic): – Interaction diagrams • Sequence diagrams • Collaboration diagrams – Statechart diagrams – Activity diagrams OOAD 4
  5. 5. Sequence Diagrams: An example OOAD 5
  6. 6. Collaboration diagram: An Example OOAD 6
  7. 7. When to use Interaction Diagrams?• Interaction diagrams are used when you want to model the behavior of several objects in a use case.  They demonstrate how the objects collaborate for the behavior. • Interaction diagrams do not give a in depth representation of the behavior.  If you want to see what a specific object is doing for several use cases use a state diagram.  To see a particular behavior over many use cases or threads use an activity diagrams. OOAD 7
  8. 8. Messages are passed between objects, andmay contain parameters (e.g., message name(parameter list))
  9. 9. Sequence Diagrams• Describing the behavior of a system by viewing the interaction between the system and its environment• Shows the objects participating in the interaction by their life lines and the messages they exchange• Shows an interaction arranged in a time sequence OOAD 9
  10. 10. Elements of a sequence diagram• Objects: represented by boxes at top of diagram.• Lifeline: the time during which an object exists.• Messages: means by which objects communicate with each other.• Activation: the time period during which an object performs an operation. OOAD 10
  11. 11. Objects/ClassesClient ATMMachine SavingAccount Insert ATM card Request PIN Enter PIN code Verify PIN code PIN valid Request amount activation Enter amount Process transaction Transaction successful Dispense cash Print receipt lifeline
  12. 12. Collaboration Diagrams• Also known as Communication diagrams• Represents a collaboration, which is a set of objects related in a particular context, and interaction, which is a set of messages exchanged among the objects within the collaboration to achieve a desired outcome• sequences of messages are shown by numbering OOAD 12
  13. 13. 1: insert ATM card 3: enter PIN code 7: enter amount :ATMMachine:Client 2: request PIN 6: request amount 10: dispense cash 4: verify PIN code 11: print receipt 8: process transaction 5: valid PIN code 9: transaction successful :SavingAccount
  14. 14. Sequence Vs Collaboration Sequence Diagram: – Dynamic behavior of a set of objects arranged in time sequence, new objects added to the right – Good for real-time specifications and complex scenarios – easier to read Collaboration Diagram : – Shows the relationship among objects. – Does not show time – Objects are arranged in a graph or network format• Both are used to examine the behavior of objects within a single use case OOAD 14
  15. 15. How to draw sequence diagram? 9-15
  16. 16. Drawing Sequence Diagrams Determine the context of the sequence diagram Identify the object that are participate in the sequence Set of the lifeline for each object Lay out of messages from the top to the bottom of the diagram based on the order in which they sent Add the execution occurrence to each object’s lifeline Validate the sequence diagram
  17. 17. Identifying Classes/Objects• Noun phrase approach – read through the requirements or use cases looking for noun phrases• Some classes are implicit or taken from general knowledge• Carefully choose and define class names OOAD 17
  18. 18. Use Case: Withdraw savingA customer wants to draw money from his bank account.He enters his card into an ATM (automated teller machine).The ATM machine prompts “ Enter PIN”. The customerenters his PIN. The ATM (internally) retrieves the bankaccount number from the card. The ATM encrypts the PINand the account number and sends it over to the bank. Thebank verifies the encrypted account and PIN number. If thePIN number is correct, the ATM displays, “Enter Amount”.Draws money from the bank account and pays out theamount. OOAD 18
  19. 19. Use Case: Withdraw savingUse Case: Withdraw SavingActors: Bank ClientFlow of Events:5. Bank client insert ATM card into ATM machine6. ATM machine request PIN code7. Bank client enter PIN code8. Verify PIN code entered with saving account9. ATM machine request amount if the PIN is valid10. Bank client enter the required amount11. Process the transaction in the client account12. ATM machine dispense cash13. ATM machine print receipt when the transaction completedAlternative Flow of Events• Invalid PIN code entered. Indicate error message. Return step 3. OOAD 19
  20. 20. Identifying Classes – noun phrase approach (example)• ATM System – Bank Client – ATM Card – ATM Machine – Savings Account – Cash – Message OOAD 20
  21. 21. Client ATMMachine SavingAccount Insert ATM card Request PIN Enter PIN code Verify PIN code PIN valid Request amount Enter amount Process transaction Transaction successful Dispense cash Print receipt
  22. 22. Another example … OOAD 22
  23. 23. ATM System ATM approval Deposit amount Client Withdraw amountUse case: ATM approval2. Insert ATM card3. Request PIN4. Enter PIN5. Verify PIN6. Display message to client
  24. 24. Client ATM Machine ClientDatabase Use case: ATM approval 2. Insert ATM card 3. Request PIN 4. Enter PIN 5. Verify PIN 6. Display message to client
  25. 25. ATM System ATM approval Deposit amount Client Withdraw amountUse case: Withdraw amount2. Request withdrawal amount3. Enter withdrawal amount4. Check account5. Verify sufficient funds6. Eject cash
  26. 26. • Object naming – Syntax: [objectName]:[className] – Include object (instance) names when objects are referred to in messages or when several objects of the same type exist in the diagram – Name classes consistently with your class diagram Object A: Class A Object B: Class B :User messageA() messageB(“string”) messageC()
  27. 27. Stereotypes of Analysis Classes Classes or objects can be classified into one of the following three stereotypes: – Entity – to hold data – Boundary – used by actors to interact with the system For example: Customer place order, interact using a order form. – Control – coordinating behavior in the system For example: control the activities in the transaction (i.e., rules, calculations)
  28. 28. Stereotypes of Analysis Classes Is an object relation that is extended to include responsibilities
  29. 29. Stereotypes of Analysis Classes Is an object relation that is extended to include responsibilities
  30. 30. Stereotypes of Analysis Classes A boundary class provides the interface between an actor and use case. The actor can be a human or an external system. Encapsulates connections between actors and use cases
  31. 31. Stereotypes of Analysis Classes A boundary class provides the interface between an actor and use case. The actor can be a human or an external system. Encapsulates connections between actors and use cases
  32. 32. Stereotypes of Analysis Classes A control class coordinates the tasks and captures the main logic in a use case. Mostly performs behaviors associated with inner workings of use cases
  33. 33. Typically, actorsinteract withboundaryclasses, which inturn interact withcontrol classes,which in turninteract withentity classes.
  34. 34. Operations(behaviors) aredepicted in thelower third of aclass box.Operations fulfillthe class’sresponsibilities.
  35. 35. Modeling Behavior Activity Diagram State Diagram OOAD 40
  36. 36. Activity Diagram: An example OOAD 41
  37. 37. When to use Activity Diagram?• The main reason to use activity diagrams is to model the workflow behind the system being designed. • Activity Diagrams are also useful for: analyzing a use case by describing what actions need to take place and when they should occur;  describing a complicated sequential algorithm;  and modeling applications with parallel processes. OOAD 42
  38. 38. Activity DiagramFocus on flow of activity of internal process in objectsimilar to flowchartdescribe changes in activity in a procedureinformation from use case scenario or event flow can be used to describe activity diagram.Used to provide detail for complex algorithms OOAD 43
  39. 39. Activity Diagram (cont.)• Purpose: – Modeling human task – Describe system’s function – Describe logic operation• Elements in activity diagram: Activity Transition Decision OOAD 44
  40. 40. Example of Activity Diagram for Register Course startFill form Select course [No] Submit to PA approve? [Yes] Register course end
  41. 41. Example of Activity Diagram for ATM AuthorizationEnter card Read card Enter PIN Request PIN [No] Verify PIN valid? [Yes] Select other service
  42. 42. Swimlane - partition an activity diagram so that parts in the swimlane relevant to that activities in the partition - helpful in investigating responsibilities for interactions and associations between objects and actorsOOAD 47
  43. 43. Activity diagram withsynchronization bars –split into multiple pathsand multiple pathscombined into a singletransitionTop synchronization bar isa fork.Bottom synchronizationbar is a join. OOAD 49
  44. 44. OOAD 50
  45. 45. When to use State Diagram?• Use state diagrams to demonstrate the behavior of an object through many use cases of the system. • Only use state diagrams for classes where it is necessary to understand the behavior of the object through the entire system OOAD 51
  46. 46. What is a State Diagram?• A diagram that captures the behavior of an object by specifying the sequence of states it goes through during its lifetime in response to events, together with the responses to those events• describe changes in state in a procedure• Also called statechart diagram or state machine diagram• State – a condition or situation during the life of an object at which time it satisfies some condition, performs some activity, or waits for some event. OOAD 52
  47. 47. What is a State Diagram? (cont.)• A state diagram to describe the behavior (i.e., state changes) of a single class according to events and messages which class sends and receives• A state diagram can also clarify a use case – to specify the actions the use case can take in accordance with varying conditions of the system• E.g., a use case ‘enroll course’, the state can be full, opened, and closed. OOAD 53
  48. 48. State Diagram ExampleInvoice created Invoice destroyed Paying Unpaid Paid
  49. 49. Transition Notation State 1 Event(parameters) [condition] /action State 2 do/activity 1 ... Start state transition End stateExample: Event(parameters) [condition]mouse_button_clicked(right_button)[inside the window]Example: /action/calculate amount
  50. 50. State Notation Name compartment Action labels OOAD 56
  51. 51. Recap• After studying this chapter we learned to: – Understand how to structure requirements with interaction diagram, activity diagram and state machine diagram. – Explain the element of sequence diagrams, activity diagram and state machine diagram. – Construct sequence diagrams, activity diagram and state machine diagram

×