Interaction Diagrams PB007 Software Engineering I Bruno Rossi 02. 12. 2015 Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 1 / 15 Interaction Diagrams Interaction diagrams model the cooperation of classes/objects/actors for the implementation of use cases (or parts of them). We distinguish 4 main types, each of which gives a view of a different aspect of the interaction: 1. Sekvenčný diagram (sequence diagram) captures the communication between classes/objects with an emphasis on the temporal sequence when passing messages. 2. Komunikačný diagram (communication diagram) captures communication with an emphasis on relationships between classes/objects. Interaction Diagrams 02. 12. 2015 2/15 Interaction Diagrams II 3. Časový diagram (timing diagram) model time constraints of the interactions of objects in real time. 4. Diagam prehíadu interakcií (interaction overview diagram) is a special case of activity diagram, which shows a top view of the connections between the complex sub-interactions. Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 3 / 15 Sequence diagram Sequence diagrams show the interaction as a time-ordered sequences of messages between objects/classes/actors. Basic elements: • Actors, classes, objects • Lifelines • Activations (focus of control) • Messages • Combined Fragments Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 4 / 15 Sequence diagram - Example sd AddCourse 0 A :Registrar synchronous message lifeline :RegistrationManager The Registrar selects Iradd course". The system creates the new Course. addCourse("UML") k notes can form a "script" describing the flow object creation message : create » uml:Course activation message return object is created at this point Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 5/15 Sequence diagram - Example II sd DeleteCourse O A Registrar : Registration Manager unnl:Course deleteCourse("UMI_y I self delegation nested activation <---------------------- J~^) findCourse("UML") «destroy» object is deleted at this point Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 6/15 Sequence diagram - Combined Fragments Combined fragments divide the sequence diagram in more areas with different behavior. Each combined fragment is marked with an operator, one or more operands, and condition(s). The most important operators are: • opt (option) - has one operand, which is triggered only if the defined condition is met • alt (alternatives) - the operand whose condition is evaluated to true will be launched. • loop - repeated execution of the operand • break - operand is executed if it meets any conditions and terminate the execution cycle Interaction Diagrams 02. 12. 2015 7/15 Sequence diagram - Combined Fragments II sd ManageBasket J :Customer :ShoppingBasket item: Item getltem () alt [changeQuantity] setQuantity() opt[ item.quantity = 0 ] J [deleteltem] «destroy» «destroy» -----------1. &-■—% Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 8/15 Sequence diagram - Combined Fragments III sd FindCourse( name : String ): CourseJ :RegistrationManager courses course:Course loop [for each course in coursesjj courseName= getName() brea < [name = courseName] J < <............ course null Interaction Diagrams 02. 12. 2015 9 / 15 Communication Diagram Communication Diagrams capture the interactions of objects/classes tjat communicate with each other. The basic elements: • Actors, classes, objects • connections (links) Messages Interaction Diagrams 02. 12. 2015 10 / 15 Communication Diagram - Example sd AddCourses 7 sequence number message / Q 1:addCourse("UML") - 2: addCourse( "MDA") A :Registrar link lifeline uml:Course t 1.1: «create» :RegistrationManager 2.1: «create» mda:Course object creation message Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 11 / 15 Communication Diagram - Iterations Iterations are expressed in communication diagram using the iteration expression. Syntax: * [loop min, max [condition]] iteration specifier sd PrintCourses 7^ iteration clause _A_ 1.1* [for i = 1 to n]: printCourse( i)-► 1: printCourses()-► :RegistrationManager : Registrar 1.1.1: print() [i]:Course sd PrintCourses 7 1: printCourses()-► :RegistrationManager registrar courses * j,.„ * printO :Course -'s)"_. Vs Interaction Diagrams 02. 12. 2015 12 / 15 Communication Diagram - Branching Branching in the communication diagram is obtained by adding guarding conditions to communications. The message is sent only in case that the condition evaluates to true. sd RegisterStudentForCourseJ 1.1: student = findStudent( "Jim") -► 1.2: course = findCourse( "UML") -► 1: register ("Jim", "UML") 1.4 [Ifound]: error() :Registrar found = (student != null) & (course != null) 5 :RegistrationManager I 1.3 [found]: register( student) \ guard condition course:Course • Open the use case model and the classes and for each use case look at the objects that are involved in the various functionalities • Select the 5 most interesting (sufficiently complex) use cases • Model 2 of them (the simpler ones) by means of a communication diagram • Model the remaining 3 by means of sequence diagrams 9 when modelling the interaction diagrams, update the class diagram with operations that might be necessary • OPTIONAL TASK: For the next week you can also try to develop a sequence diagram from last year's exam and then get the feedback next time (see IS for Week 10 for the link to the exam paper). • Upload the PDF report into folder (Week 10). Deadline: 07.12.15 23:59 (Groups 2,3) Interaction Diagrams 02. 12. 2015 14 / 15 Customization of PDF Reports Generate PDF Content j Options j] page Setup | Cover Page | Header/Footer | -Options— Generate table of contents p Generate table of figures p Generate diagrams Image type : [sVG p Generate diagram type title P Generate diagram properties p Generate diagram summary I- Include extra details |~~ Suppress element with blank documentation in summary table p Generate reference (file/URL) link I- Generate model elements/diagrams link |~~ Skip heading for empty model element section I- Convert multiline model heading to single line I- Show multiline model name |~~ Treat HTML content as HTML source |~~ Suppress details if duplicated p Table cell keep together with page Wrap : Word wrap Shape type style : |lcon ▼ | RTF content appearance : Document Info | Watermark | rDetails — Preserve formatting |~~ Properties |~~ Project management properties ~ Relationships p Quality information \~ References I- References documentation p Sub-diagrams V Include sub-diagram details \~ Comments Sort by Date/Time: |Descending ^ \~ Tagged values r ORM Class Details p Use Case Details rFont Font: j Unspecified ^ | Reset Reset to Default Set as Default Generate Cancel Apply Help Software Engineering I (PB007) Interaction Diagrams 02. 12. 2015 15 / 15