Interaction Diagrams CS 124
Object collaboration A use case carried out involves objects and interaction or collaboration between these objects Method calls between objects This collaboration is depicted in the UML through an Interaction Diagram Two types: Collaboration diagram Sequence diagram
Example: Collaboration Diagram Checkout Screen :Borrower :Book 1: checkIfDelinquent() 3: borrowBook() 2: checkIfAvailable() 4: setBorrower()
Interaction (Collaboration) Diagram Notation Rectangles: Classes/Objects Arrows: Messages/Method Calls Labels on Arrows sequence number (whole numbers or X.X.X notation) method name (the message passed) more details, if helpful and necessary (iterators, conditions, parameters, types, return types)
Methods Interaction Diagrams suggest/imply methods for classes Has consequences on detailed class diagram The label(s) of an arrow should be a method of the class the arrow points to Library System Borrower class should have at least two methods (checkIfDelinquent and borrowBook)
Including Conditions and Types Checkout Screen r:Borrower b:Book 1: delinq = checkIfDelinquent():boolean 3:[!delinq & avail] borrowBook(Book b) 2: avail = checkIfAvailable():boolean
Creating an Object new means a constructor is being called Implies object creation :Customer :CustomerList 1: addCustomer(custdetails) :Encoder 2: new Note: this means the addCustomer method will contain code that creates a Customer object
Iteration * is an iterator means the method is called repeatedly :Branch :Store 1: printSalesSummary() :Manager 2: * getTotalSales() Note: Store needs data from all branches to produce a summary
Sequence Diagram Variant of an interaction diagram that emphasizes sequence Objects shown as boxes on top of the diagram Dashed vertical line below the box: object’s lifeline Activation bar to indicate the object’s activation Sequence number unnecessary because top to bottom calling sequence is assumed Message notation the same as for collaboration diagrams
Collaboration versus Sequence Diagrams Use collaboration diagrams when you want to make use of a two-dimensional layout of interacting objects Ok when there aren’t that many objects Use sequence diagrams when layout doesn’t help in presentation and when you want to clarify calling sequence