Modeling Behavior with Sequence Diagrams Dumitru Radoiu Dumitru Radoiu Spring 2009 PETRU MAIOR UNIVERSITY Object-Oriented World time OO Analysis Create the vocabulary Requirements OO Design Give vocabulary ocabu a y behavior (model the system) OO Programming Program the model ode Deliverables Activity UML Diagram Understand System Usage Use Case Diagram Identify Classes Identify Classes High Level Class Diagram 9 High Level Class Diagram Define Workflows Activity Diagram 9 9 Object-Oriented World time OO Design OO Analysis Create the vocabulary Requirements Give vocabulary ocabu a y behavior (model the system) OO Programming Program the model ode A ti it Activity UML Di UML Diagram Identify interactions among objects Sequence and Collaboration Diagrams Analyze state changes l h Sate Diagrams Refine class diagrams Class Diagrams Deliverables Agenda • • • • • Why We Model Sequence Diagrams Why We Model Sequence Diagrams Notation How to Use Messages for Communications Learn Other techniques Used in Sequence Diagrams Model a Sequence Diagram: Case Study Why we model sequence diagrams? diagnose car Mechanic fix car drive car Car owner Why we model sequence diagrams? diagnose car Mechanic [talk] Diagnosis Mechanic Car Agenda • • • • • Why We Model Sequence Diagrams Why We Model Sequence Diagrams Notation How to Use Messages for Communications Learn Other techniques Used in Sequence Diagrams Model a Sequence Diagram: Case Study Why we model sequence diagrams? diagnose car Mechanic Messages [talk] Diagnosis Mechanic A ti Objects Active Obj t Car Types of Messages Synchronous Return Asynchronous Flat The execution waits until the message is i received i d and d completed l t d Message received an completed; control is returned to calling the active object The execution does not wait for the message to be received and completed; continues I have no idea what type of message is; or I don’t care Why we model sequence diagrams? Diagnosis Car M h i Mechanic Car Diagnosis Mechanic Turn On Turn On Set to check Diagnose Lifeline Fix the problem Turn Off Turn Off Lifeline and time ObjectTwo ObjectOne Mechanic MessageOne MessageTwo MessageThree MessageFour MessageFive Time flflow; Ti messages displayed in chronological g order UML Glyphs for Sequence Diagrams Active objects Lifeline Messages types Flat ObjectName Synchronous Return A Asynchronous h UML Glyphs for Sequence Diagrams WebInterface Email Teacher Login Lookup Student Component p not part of our system Distribute Grades Send Email with Grades Logout Agenda • • • • • Why We Model Sequence Diagrams Why We Model Sequence Diagrams Notation How to Use Messages for Communications Learn Other techniques Used in Sequence Diagrams Model a Sequence Diagram: Case Study How to use Synchronous Messages Database Wrapper W bI t WebInterace Teacher Login Teacher Validate User [successful validation] Lookup Student Info Retrieve Student Info How to use Asynchronous Messages Log WebInterace Teacher Login Teacher Log Logon Attempt [ [successful logon] g ] Log Successful Logon [unsuccessful logon] Log Unsuccessful Logon [successful validation] Lookup Student Info Log Student Retrieval [successful validation] Change Student Info [successful logon] Logout Log g Changes g to Student Info Agenda • • • • • Why We Model Sequence Diagrams Why We Model Sequence Diagrams Notation How to Use Messages for Communications Learn Other techniques Used in Sequence Diagrams Model a Sequence Diagram: Case Study Creating Objects ObjectOne <<create>> ObjectTwo message The lifeline is destroyed <<destroys>> X Creating Objects WebInterface Validate User [logged in] Retrieve User [invalid user] <<create>> MessageBox [invalid user] Display Error Message [invalid user] <<destroys>> X Database Wrapper Using States ObjectOne ObjectTwo States belong to objects and exist directly on their lifeline State Using States WebInterface Request New Account Database Wrapper create <<create>> Account Information Populate with Account Info Ready Change Account Info Change Data Modified Save Data Ready Branching ObjectOne ObjectTwo ObjectThree Starting point the same [[condition two]] [condition one] Ending height the same Branching FileSystem Editor Load File BinaryViewer TextViewer [binary file] [[text file]] Alternative flows ObjectTwo ObjectOne [condition two] [[condition one]] Alternative flows FileSystem Editor Developer Exit App [delete file] [ [save file] fil ] Agenda • • • • • Why We Model Sequence Diagrams Why We Model Sequence Diagrams Notation How to Use Messages for Communications Learn Other techniques Used in Sequence Diagrams Model a Sequence Diagram: Case Study Model a Sequence Diagram: Case Study The following requirements are for a computerized grading system: •The The teacher views the grades for a student successfully •The teacher attempts to view the grades for a student but the student doesn’t exist in the system •The teacher attempts to view the grades for a student but the student does not have any grades 1. 2. 3. 4. Decide what workflows you will model Decide what workflows you will model Lay out your objects from left to right Include messages and conditions to build each workflow Draw a generic diagram to combine the separate diagrams 2. Lay Out Objects Teacher WebInterface Database Wrapper StudentInfo Student Grades 3. Include Messages and Conditions Teacher WebInterface Database Wrapper StudentInfo Student Grades Request Student Info Get Student Data Load Student Return Student Info Load Grades Return Grades for Student Return Student Info Display Student Info 4. Include conditions Teacher WebInterface Database Wrapper StudentInfo Request Student Info Get Student Data Load Student (Student not found) (Failure) <<create>> M MessageBox B Display Error <<destroys>> destroys X Student Grades