Download presentation
Presentation is loading. Please wait.
Published byLeslie Clark Modified over 9 years ago
1
1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models
2
Advanced Modeling with UML2 Behavioral Elements of UML Metamodel
3
3 Specifying behavior using UML Class models describe objects and their relationships Behavior can be specified in terms of operation pre and postconditions, but behavior is not the primary focus of a class model Behavioral models in the UML State models: describe control aspects of a system – provides descriptions sequences of operations without regard for what the operation do. Interaction models: describe interactions among objects Activity models: description of a behavioral feature expressed in terms of sequences of steps.
4
4 How things happen in the UML An action is executed by an object It May Change the contents of one or more variables Invoke an operation on another object Send a signal to another object Either one will eventually cause the execution of a procedure on the target object… …which will cause other actions to be executed, etc. Successor actions are executed Determined either by control flow or data flow
5
5 Sequence Models
6
6 Overview Objects interact to accomplish use case goals. Object interactions are described in terms of Collaborations: descriptions of object structures that support required behaviors Interactions: descriptions of communication structures that support required behaviors A sequence diagram Models sequential logic, an ordered sequence of interactions between objects as described for example, by a use case Interaction/sequence diagrams allow one to view only the parts of a system involved in accomplishing use case goals.
7
7 A class diagram for a Student Registration Application ***** ****** * CourseSection requestToRegister Registration Course getPrerequisite Student addToSchedule hasPassedCourse addToRegistrationList 1 1 1 Diagram shows structure not behaviour.
8
8 Sequence diagrams A sequence diagram shows the sequence of messages exchanged by the set of objects performing a certain task The objects are arranged horizontally across the diagram. An actor that initiates the interaction is often shown on the left. The vertical dimension represents time. A vertical line, called a lifeline, is attached to each object or actor. The lifeline becomes a broad box, called an activation box during the live activation period. A message is represented as an arrow between activation boxes of the sender and receiver. A message is labelled and can have an argument list and a return value. requestToRegister addToSchedule > :Student :Registration :CourseSection addToRegistrationList
9
9 Sequence Diagram: basic constructs objectName : Class object symbol lifeline activation other:Type message name (…) return : Class create new (…) delete m1()
10
10 Different kinds of arrows Synchronous - Procedure call or other kind of nested flow of control Asynchronous, flat flow Return
11
11 Example: different arrows callerexchangecallee Flat Flow lift receiver dial tone dial digit ringing toneringing signal lift receiver teller: Order: Article Nested Flow getValue price getName 1 2 3 4 5 6 78 910 Different traces are possible!
12
12 Extended sequence diagram example requestToRegister(aStudent) addToSchedule() aStudent: Student :Registration :CourseSectionGUI requestToRegister() :Course [hasPrerequisite] > prereq := getPrerequisite() hasPrerequisite:= hasPassedCourse(prereq) addToRegistrationList()
13
13 If an object’s life ends, this is shown with an X at the end of the lifeline Sequence diagrams – an example with object deletion cancelBooking deleteFromItinerary cancel :PassengerRole :Booking:SpecificFlight deleteFromPassengerList
14
14 A more complex Sequence Diagram (UML 2.0) Frame and Name Lifeline is an object Interaction Occurrence Combined Fragment Plain asynchronous message
15
15 Combined Fragments A combined fragment defines an expression of interaction fragments. A combined fragment is defined by an interaction operator and corresponding interaction operands. Through the use of CombinedFragments the user will be able to describe a number of traces in a compact and concise manner – UML Spec.
16
16 Combined Fragment
17
17 Combined fragment interaction operators Alternatives (alt) choice of behaviors – at most one will execute depends on the value of the guard (“else” guard supported) Option (opt) Special case of alternative Break (break) Represents an alternative that is executed instead of the remainder of the fragment (like a break in a loop) Parallel (par) Concurrent (interleaved) sub-scenarios Negative (neg) Identifies sequences that must not occur
18
18 Combined fragment interaction operators Critical Region (region) Traces cannot be interleaved with events on any of the participating lifelines Loop (loop) Optional guard: [,, ] No guard means no specified limit
19
19 Critical region call(112)
20
20 Combined fragments and data: loop loop Choice Operand Separator Guarding InteractionOperand with an InteractionConstraint
21
21 sd ATM-transaction client:atm:dbase: Referencing interaction diagrams insertCard CheckPin ref alt [chk= OK] [else] error(badPIN) DoTransaction ref sd CheckPin client:atm:dbase: askForPIN data(PIN) check(PIN) result(chk) Interaction Frame Lifeline is one object or a part Interaction Occurrence Combined (in-line) Fragment
22
22 Decomposition with global constructs corresponding to those on decomposed lifeline Decomposed lifeline Detailed context Decomposing Lifelines
23
23 Local variables: money transfer sequence diagram Local variables
24
24 Creating Interaction Model Set interaction context Use Case scenario Identify (controller) object responsible for handling the event initiating the interaction Identify objects that collaborate with the controller (collaborators). Specify message passing sequence that handles the initiating message.
25
25 Interaction modeling tips Set the context for the interaction. Include only those attributes of the objects that are relevant. Express the flow from left to right and from top to bottom. Put active objects to the left/top and passive ones to the right/bottom. Use sequence diagrams to show the explicit ordering between the stimuli when modeling real-time
26
26 Example 1: problem specification Withdrawing money from an account When withdrawing money from his account, John inserts his card and inputs his password. He then selects the account from which to withdraw money and enters the amount of money to withdraw. He then collects his money and receipt.
27
27 Exercise: create a sequence diagram for a scenario of a self- service machine. The main functions of a self-service machine is to allow a customer to buy a product(s) from the machine (candy, chocolate, juice...). A customer wants to buy some of the products offered by the self-service machine. First of all he/she inserts money into the machine and selects one or more products. The money travels to the register and the register checks to see whether the selected product is in the dispenser. The register updates its cash reserved and asks the dispenser to deliver the product to the front of the machine.
28
28 ______________________ Devon M. Simmonds Computer Science Department University of North Carolina Wilmington _____________________________________________________________ Qu es ti ons? The End
29
Additional Slides 29
30
Money Withdrawal 30
31
31 UML Metamodel – Interactions
32
32 UML Metamodel – Interactions
33
33
34
34
35
35 Interaction Use
36
36 A simple sequence diagram for a Register Student use case requestToRegister addToSchedule > :Student :Registration :CourseSection addToRegistrationList ***** ****** * CourseSection requestToRegister Registration Course getPrerequisite Student addToSchedule hasPassedCourse addToRegistrationList 1 1 1
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.