Object-Oriented Design Lecture 13: Use Case Realizations Sharif University of Technology 1 Department of Computer Engineering
Analysis Workflow: Analyze a Use Case • The analysis workflow consists of the following activities: • Architectural analysis • Analyze a use case • Outputs: • analysis classes • use case realizations • Analyze a class • Analyze a package 2 Sharif University of Technology
Use Case Realizations • Use case realizations show how instances of analysis classes interact to realize the functional requirements specified by a use case. • Each use case realization realizes exactly one use case. • Use case realizations consist of: • analysis class diagrams - these should "tell a story" about one (or more) use cases; • interaction diagrams - these demonstrate how objects interact to realize the use case behavior; • special requirements - you always uncover new requirements during use case realization and you need to record these; • use case refinement - you may need to change a use case as you begin to realize it. 3 Sharif University of Technology
Lifelines • A lifeline represents a participant in an interaction - how an instance of a classifier participates in the interaction. • Each lifeline has an optional name, a type, and an optional selector. • Each lifeline is drawn with the same icon as its type. • Underline the name, type, and selector to show actual instances . 4 Sharif University of Technology
Messages • A message represents a specific kind of communication between two lifelines in an interaction. 5 Sharif University of Technology
Interaction Diagrams • Sequence diagrams - emphasize time-ordered sequence of message sends. • Communication diagrams - emphasize structural relationships between objects. • Interaction overview diagrams - emphasize relationships between interactions. • Timing diagrams - emphasize real-time aspects of interactions. 6 Sharif University of Technology
Sequence vs. Communication diagram • Sequence Diagrams: show object interactions arranged in time sequence, vertically • Communication Diagrams: show object interactions arranged as a flow of objects and their links to each other, numerically • Semantically equivalent, structurally different • Sequence diagram emphasize time ordering • Communication diagrams make object linkages explicit 7 Sharif University of Technology
Sequence Diagrams: General Notation • Time runs top to bottom. • Lifelines run left to right: • lifelines have dashed vertical tails that indicate the duration of the lifeline; • lifelines may have activations to indicate when the lifeline has focus of control; • organize lifelines to minimize the number of crossing lines. • Place explanatory scripts down the left-hand side of the sequence diagram. • State invariants - place state symbols on the lifeline at the appropriate points. • Constraints - place constraints in {} on or near lifelines. 8 Sharif University of Technology
UML sequence diagrams • sequence diagram : an "interaction diagram" that models a single scenario executing in the system • perhaps 2nd most used UML diagram (behind class diagram) • relation of UML diagrams to others: • CRC cards -> class diagram • use cases -> sequence diagrams • the axes in a sequence diagram: • horizontal: which object/participant is acting • vertical: time (down -> forward in time) 9
Sequence Diagrams: Realization Example 1 12 Sharif University of Technology
Sequence Diagrams: Realization Example 2 13 Sharif University of Technology
Sequence Diagrams: Realization Example 3 Use Case 14 Sharif University of Technology
Sequence Diagrams: Realization Example 3 Sequence Diagram 15 Sharif University of Technology
Combined Fragments • Combined fragments - areas within a sequence diagram with different behavior. • The operator defines how its operands execute. • The guard condition defines whether its operand executes. • The operand contains the behavior. 16 Sharif University of Technology
Combined Fragments: Operators – opt and alt • opt - there is a single operand that executes if the condition is true (like if ... then). • alt - the operand whose condition is true is executed. 17 Sharif University of Technology
Combined Fragments: Operators – opt and alt 18 Sharif University of Technology
Combined Fragments: Operators – loop and break • loop - loop min, max [condition] • loop or loop * - loop forever; • loop n, m - loop (m – n + 1) times; • loop [ booleanExpression ] - loop while booleanExpression is true; • loop 1, * [ booleanExpression ] - loop once then loop while booleanExpression is true; • loop [for each object in collectionOfObjects] - execute the body of the loop once for each object in the collection; • loop [for each object in className] - execute the body of the loop once for each object of the class. • break - if the guard condition is true, the operand is executed, not the rest of the enclosing interaction. 19 Sharif University of Technology
Combined Fragments: Operators – loop and break Syntax 20 Sharif University of Technology
Combined Fragments: Operators – loop and break Example 21 Sharif University of Technology
Combined Fragments: Operators – Other • ref - the combined fragment refers to another interaction. • par - all operands execute in parallel. • critical - the operand executes atomically without interruption. • seq - operands execute in parallel subject to the following constraint: events arriving on the same lifeline from different operands occur in the same sequence as the operands occur. • strict - the operands execute in strict sequence. • neg - the operand shows invalid interactions. • ignore -lists messages that are intentionally omitted from the interaction. • consider -lists messages that are intentionally included in the interaction. • assert - the operand is the only valid behavior at that point in the interaction. 22 Sharif University of Technology
Example sequence diagram sd Example StoreFront Cart Inventory loop AddItem ReserveItem Checkout ProcessOrder ConfirmOrder PlaceItemInOrder 23
(De)centralized system control • What can you say about the control flow of each of the following systems? • centralized? • distributed? 24
Communication (aka Collaboration) Diagrams • Communication diagrams - emphasize the structural aspects of an interaction: • lifelines are connected by links; • messages have a sequence number - they are numbered hierarchically according to the nesting of the focus of control. 27 Sharif University of Technology
Communication (aka Collaboration) Diagrams • Objects are rectangular icons • e.g., Order Entry Window, Order, etc. • Messages are arrows between icons • e.g., prepare() • Numbers on messages indicate sequence • Also spatial layout helps show flow • Which do you prefer: sequence or communication? • Fowler doesn’t use communication diagrams • Show flow clearly, but awkward modeling alternatives 28 Sharif University of Technology
Iteration • Iteration - use an iteration specifier (*) and an optional iteration clause on the message. • The iteration clause specifies the number of times to loop. • You can use natural language, pseudocode, source code, or sequence diagram loop notation for the iteration clause. • Iteration over a collection of objects: • Denoted by showing the role name and multiplicity (>1) on the target end of the link and prefixing the message with *. • The message is sent to each object in turn. • Use the parallel iteration specifier *// to indicate that messages are executed in parallel. 29 Sharif University of Technology
Iteration - Example 30 Sharif University of Technology
Branching • Branching - prefix messages with guard conditions. The message executes if the guard condition is true. • It can be hard to show branching clearly on a communication diagram - for complex branching, use sequence diagrams instead. 32 Sharif University of Technology
Communication and Class Diagrams • Links in a communication diagram directly correlate to associations between classes in a class diagram
Interaction Occurrences • Interaction occurrences: references to another interaction. • The flow of the referenced interaction is included in the flow of the referencing interaction. • Parameters - interaction occurrences may have parameters - use normal parameter notation. • Gates - inputs and outputs of interactions: • a point on the sequence diagram frame that connects a message outside the frame to a message with the same signature inside the frame. • Use parameters when you know the source and destination of all messages - use gates when you don't. 36 Sharif University of Technology
Interaction Occurrences – Example Use Case and Class Diagram 37 Sharif University of Technology
Interaction Occurrences – Example SDs 38 Sharif University of Technology
Interaction Occurrences – Parameters 39 Sharif University of Technology
Interaction Occurrences – Gates 40 Sharif University of Technology
Communication Diagram Overview 41 Sharif University of Technology
Recommend
More recommend