1 / 44

Dynamic Modelling (1)

Dynamic Modelling (1). Prof. T.H. Tse Department of Computer Science Email: thtse@cs.hku.hk Web: http://hku.hk/thtse. Dynamic Model. Specify the behaviour of objects by describing the sequentiality control of their operations Disregard what the operations do how they are implemented

Download Presentation

Dynamic Modelling (1)

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. Dynamic Modelling (1) Prof. T.H. Tse Department of Computer Science Email:thtse@cs.hku.hk Web:http://hku.hk/thtse

  2. Dynamic Model • Specify the behaviour of objects by describing the sequentiality control of their operations • Disregard • what the operations do • how they are implemented • Represented graphically using • sequence diagrams • state machines Can also be regarded as a use case model but never as a program Can also be regarded as a design model.

  3. Event • An event occurs whenever information is exchanged between an object and an outside agent, or between two objects • Examples: Caller hangs up • Phones are disconnected • The information values exchanged are the parameters of the event • An event happens at a point in time and has noduration.

  4. ExamplesEvents with Classes and Attributes • airplane flight departs (airline, flight number, city) • mouse button pushed (button, location) • input string entered (text) • phone receiver lifted • digit dialed (digit) • engine speed enters danger zone.

  5. caller lifts receiver dial tone begins caller dials digit (2) dial tone ends caller dials digit (8) caller dials digit (5) caller dials digit (9) caller dials digit (2) caller dials digit (1) caller dials digit (8) caller dials digit (0) … called phone begins ringing ringing tone appears in calling phone called party answers called phone stops ringing ringing tone disappears in calling phone phones are connected called party hangs up phones are disconnected caller hangs up. ExampleScenario for Phone Call

  6. Sequence Diagram • A sequence diagram is a graphical representation of related scenarios • It shows: • objects as vertical dotted lines • events as horizontal arrows from the sender object to the receiver object.

  7. Sequence DiagramMain Syntax sd borrowBook :Book r1:Reader r2:Reader Time dateDue reminder time return available [mayBorrow] borrow Frame Object Life line Message Execution occurrence Condition .

  8. Asynchronous messsage • Synchronous messsage (method calls) • Reply message • Object creation message • Lost message • Found message Message Types

  9. Synchronous Message doYouUnderstand ( ) :Professor :Student

  10. Synchronous Message Combined with execution occurrence :Professor :Student Execution occurrence Caller blocked. doYouUnderstand( ) yes • Typically implemented as operation call • The routine that handles the message is completed before the caller resumes execution

  11. Return Value • Optionally indicated using a dashed arrow with a label indicating the return value • Don’t model a return value when it is obvious what is being returned, e.g., getTotal( ) • Model a return value only when you need to refer to it elsewhere, e.g., as a parameter passed in another message.

  12. Asynchronous Message • Caller does not wait for the message to be handled before it continues to execute.

  13. Example 1 Synchronous Message and Synchronous Call • Word Processor object sends a synchronous message to Printer object asking it to print a file • Word Processor object does not do anything until it receives a (software) acknowlegement from Printer object saying that the printing is complete • This is a synchronous call.

  14. :Word Processor :Printer print printComplete Caller blocked Example 1 Synchronous Message and Synchronous Call

  15. Example 2 Asynchronous Message • Word Processor object sends an asynchronous message to Printer object asking it to print a file • Printer object can print the file at any time when it is free • Word Processor object can do anything after it has sent off the asynchronous message.

  16. :Word Processor :Printer print callHelp Example 2 Asynchronous Message No execution occurrence

  17. :Order Object Creation Message • An object may create another object via an object creation message :Customer Constructor .

  18. :Professor :Student doYouUnderstand( ) no Lost Message

  19. :Professor :Student doYouUnderstand( ) no Found Message

  20. DB is queried and the result is returned as an object : ViolationsDialogue : ViolationsController : ViolationsDBProxy Clerk lookup viewButton() id=getID() getViolation(id) v: TrafficViolation v display(v) More (Syntax) ExampleLookup Traffic Violation

  21. [amount < balance]debit(amount) Condition • A condition is a Boolean function relating attributes and/or values • Example: • Conditions are used as guards on transitions • A guarded transition fires whenits event occurs and satisfies the guard condition.

  22. :Mouse :Mouse Click 1 s Highlight Open {0..1 s} Click Click Duration Constraint • Example 1: Single click • Example 2: Double click

  23. Example 1: Single click :Mouse :Mouse Click t = now Highlight Open t + 1 s • Example 2: Double click t = now Click Click t + {0..1 s} Time Constraint

  24. Control InformationCombinedFragment • CombinedFragments are used to describe control information in sequence diagrams • They are only for modeling simple combinations of scenarios.

  25. Control InformationCombinedFragments • Alternatives (alt) • Option (opt) • Parallel (par) • Critical Region (critical) • Iteration (loop) • Continuation.

  26. CombinedFragmentAlternatives (alt) • Represents a choice of behavior • At most one of the operands will be chosen • The chosen operand have an explicit or implicitguard expression that evaluates to true • An operand guarded by elsedesignates a guard that is the negation of the disjunction of all other guards in the enclosing CombinedFragment ...

  27. CombinedFragmentAlternatives (alt) • If none of the operands has a guard that evaluates to true, none of the operands are executed and the remainder of the enclosing InteractionFragment is executed.

  28. CombinedFragmentAlternatives (alt)

  29. Alt Open {0..1 s} Click Click AlternativesSingle and Double Clicks No explicit guard condition in this case. :Mouse Click 1 s Highlight

  30. CombinedFragmentOption (opt) • Designates that the CombinedFragment represents a choice of behavior where either the (sole) operand happens or nothing happens • An option is semantically equivalent to an alternative CombinedFragment where there is one operand with non-empty content and the second operand is empty.

  31. CombinedFragmentOption (opt) No explicit guard condition in this case. 31

  32. CombinedFragmentParallel (par) • Designates that the CombinedFragment represents a parallel merge between the behaviors of the operands • The EventOccurrences of the different operands can be interleaved in any way as long as the ordering imposed by each operand as such is preserved.

  33. CombinedFragmentParallel (par)

  34. CombinedFragmentCritical Region (critical) • The sequence of events in a critical region cannot be interleaved by events outside the region • Even though CombinedFragments may imply that some events may interleave, such as with the par-operator, this is prevented by defining a critical region.

  35. CombinedFragmentCritical Region (critical) • A 911-call must be contiguously handled • The operator must make sure to forward the 911-call before doing anything else. • Normal calls can be freely interleaved

  36. loop loop (3, 5) loop (3) loop (3, *) CombinedFragmentIteration (loop) [condition] Minimum of 3 iterations The same, but easier to understand

  37. CombinedFragmentContinuation

  38. CombinedFragmentContinuation • Equivalent to:

  39. CombinedFragmentWarning • Remember:

  40. CombinedFragmentWarning • The modelling of most real-life applications are usually much simpler than the examples that I have shown • Consider drawing several diagrams for modeling complex combinations • Do not use sequence diagrams for detailed modelling of algorithms • Better done using state machines, activity diagrams or pseudo-code.

  41. InteractionUse (ref ) An InteractionUse refers to an Interaction The InteractionUse is a shorthand for copying the contents of the referred Interaction where the InteractionUse is To be accurate the copying must take into account substituting parameters with arguments and connect the formal gates with the actual ones. 41

  42. InteractionUse (ref ) An InteractionUsereferring to an Interaction :EstablishAccesswith an (input) argument “Illegal PIN” An InteractionUsereferring to an Interaction :EstablishAccesswith an (input) argument “Illegal PIN” An InteractionUse without arguments referring to an Interaction :OpenDoor. 42

  43. InteractionUse (ref ) Interaction that models a behavior returning a value of Verdict Interaction that models a behavior returning a value of Verdict An InteractionUse refers to a_util_bwith value return to the attribute xcof :xxwith the value 9, and with in/out parameter where the argument is w with returning out-value 12 An InteractionUse refers to a_util_bwith value return to the attribute xcof :xxwith the value 9, and with in/out parameter where the argument is w with returning out-value 12 The return value from the Interaction is shown as a separate Lifeline a_op_b. 43

  44. InteractionUseWarning • Do you find this example difficult? • Your users will find it even more so • Avoid drawing complex sequence diagrams all together • Avoid combining many scenarios together.

More Related