170 likes | 279 Vues
Sequence diagrams and collaboration diagrams are fundamental tools in modeling object interactions in software design. While collaboration diagrams focus on the relationship between objects, sequence diagrams emphasize the order of messages exchanged. This makes sequence diagrams ideal for scenarios with complex interactions, such as logging into a system or performing transactions at an ATM. In sequence diagrams, each action is represented clearly, allowing for better understanding of processes and avoiding clutter often seen in collaboration diagrams. This guide explores both diagram types and their application through examples.
E N D
What are Sequence Diagrams? • Collaboration Diagrams allow designer to specify message flow between collaborating objects • Focus on relationship between objects • Sequence Diagrams contain the same information as Collaboration Diagrams • Focus on sequence, not relationship
What if there are many object interactions? 8:M8 Jonathon 3:M3 5:M5 1:M1 4:M4 10:M10 9:M9 7:M7 Dale 2:M2 6:M6 Michelle Collaboration Diagram is too cluttered and confusing
Sequence Diagram Jonathon Dale Michelle M1 M2 M3 M4 M5 M6 M7 M8 M9 M10
Sequence Diagrams: An Example • Logging into a system :CUSTOMER :HOMEPAGE clickLogin()
:HOMEPAGE :LOGIN PAGE display()
:CUSTOMER :LOGIN PAGE Enter user ID and Password clickOK()
:CUSTOMER :HOMEPAGE :ACCOUNT :LOGIN PAGE validateLogin(userID,password) loginOK() display() «destroy» X
:CUSTOMER :HOMEPAGE :ACCOUNT :LOGIN PAGE clickLogin() «create» display() Enter user ID and Password clickOK() validateLogin(userID,password) loginOK() display() «destroy» X
How about an ATM machine? • Basic Course (UC12: withdraw money) • Insert Card • Enter PIN • Select “Withdrawal” from Main Menu • Enter Amount • Take cash • Take card
The Cell phone Example :Speaker :Cell Radio :Dialer :Button send:Button :Display The Object Diagram for Cell Telephone System
:Speaker 1.2: Emit Tone 1*: Digit 2.1: Connect :Cell Radio :Dialer :Button 2.1.1: In Use 1.1: Display Digit 2: Send send:Button :Display The Collaboration Diagram for Cell Telephone System
Cell Phone Sequence Diagram digit:Button :Digitbutton Adapter :Dialer :Display :Speaker Buttonpressed() Digit(code) DisplayDigit(code) EmitTone(code) :Sendbutton Adapter :Dialer :Cellradio :Display send:Button Buttonpressed() Send() Connect(pno) InUse()
Create and Destroy :Dialer :CellRadio :Connection Connect(pno) Create() Connect(pno) ConnectionMade() End(pno) Disconnect(pno) Disconnected() X Destroy()
Race Conditions • Occurs when single object concurrently receives message from competing clients • Consider an incoming call on a cell phone • Cell radio detects incoming call and sounds ringer • Cell radio also informs Dialer that a call is coming in and places the dialer in a special state • In this state, the Send button, when pressed, answers the call • The send button has different meanings in different circumstances (what is this called?) • But what happens if the incoming call comes when a outgoing call is being made?
Race Condition :Sendbutton Adapter :Dialer :Cellradio :Ringer ring() Incoming call() Send() Answer() :Sendbutton Adapter :Dialer :Cellradio :Ringer Connect(pno) Send() ring() Incoming call()
Try One • A sales clerk starts a new transaction • He/she enters the transaction details (account# and product) • System retrieves product and customer details, and associated discount • Clerk confirms transaction • The system updates receivables accounts • System informs clerk that transaction is complete