Understanding UML Sequence Diagrams
UML Sequence Diagrams illustrate high-level interactions between class instances in software programs. They represent method calls and interactions among objects during program execution. The diagrams show interactions for specific circumstances like startup or button clicks. Each class/object is represented with a rectangle, and interactions are shown with lifelines and method calls. Stick figures may represent users or operating systems. Notation includes class/object names at the top of rectangles for clarity.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
UML Review Sequence Diagrams SE-2030 1 Dr. Mark L. Hornick
Sequence diagram from SE1021 Lab 9: http://people.msoe.edu/~hornick/Courses/se1021/labs/se1021_Drawing%20Program%202010%20Part%202.htm What does a Sequence diagram illustrate? SE-2030 2 Dr. Mark L. Hornick
Startup Sequence Diagram public class ATM { private static Account checking = new Account(); private static Account savings = new Account(); private ATM() { } public static void main(String[] args) { // perform some initial transactions boolean status = checking.withdraw(100); status = savings.deposit(100); } } //end ATM checking : Account ATM savings : Account main(); status = withdraw(100); status = deposit(100); SE-2030 3 Dr. Mark L. Hornick
Sequence diagrams illustrate high-level interactions (method calls) between class instances A UML Sequence Diagram represents classes and/or class instances (objects) and their interactions with one another Classes and objects can interact with one another in many different ways during the course of execution of a program A given Sequence Diagram shows just one interaction for a specific circumstance (e.g. startup, shutdown, processing a single button click, ) checking : Account ATM savings : Account status = withdraw(100); status = deposit(100); main(); SE-2030 4 Dr. Mark L. Hornick
Notation & representation The name of the class appears at the top of a Sequence Diagram rectangle, which can also (optionally) include the name of the object representing a particular instance of that class: UML Syntax: [<object_name> ]: <class_name> chkAcct : Account chkAcct is the name of the reference to an instance of an Account SE-2030 5 Dr. Mark L. Hornick
Notation and representation checking : Account ATM cm: CashMachine withdraw(100); balance = checkAcctBalance(); This represents the withdraw() method calling the checkBalance method in the same class main(); This rectangle represents the duration of the main() method call amountOK = hasCash(100); The stick figure represents the user or the op sys dispenseCash(100); status status = deposit(100); wasAccepted = acceptEnvelope(); Time passes in this direction The vertical dotted lines are called lifelines SE-2030 6 Dr. Mark L. Hornick
Sometimes, you may want to show conditional logic (selection) in a Sequence Diagram -although this is usually too much detail to show at this level checking : Account ATM cm: CashMachine withdraw(100); balance = checkAcctBalance(); This represents the withdraw() method calling the checkBalance method in the same class main(); This rectangle represents the duration of the main() method call [if balance>100] amountOK = hasCash(100); Time passes in this direction [if amountOK==true] dispenseCash(100); status deposit(100); wasAccepted = acceptEnvelope(); The vertical dotted lines are called lifelines SE-2030 7 Dr. Mark L. Hornick
Similarly, you can illustrate iteration checking : Account ATM cm: CashMachine withdraw(100); balance = checkAcctBalance(); This represents the withdraw() method calling the checkBalance method in the same class main(); This rectangle represents the duration of the main() method call amountOK = hasCash(100); Time passes in this direction *[while<100]dispenseCash(20); status deposit(100); wasAccepted = acceptEnvelope(); The vertical dotted lines are called lifelines SE-2030 8 Dr. Mark L. Hornick