Sequence Diagrams UML sequence diagrams n sequence diagram

  • Slides: 44
Download presentation
Sequence Diagrams

Sequence Diagrams

UML sequence diagrams n sequence diagram: an "interaction diagram" that models a single scenario

UML sequence diagrams n sequence diagram: an "interaction diagram" that models a single scenario executing in the system n n perhaps 2 nd most used UML diagram (behind class diagram) relation of UML diagrams to other exercises: n use cases -> sequence diagrams 2

Key parts of a sequence diag. n participant: an object or entity that acts

Key parts of a sequence diag. n participant: an object or entity that acts in the sequence diagram n n n sequence diagram starts with an unattached "found message" arrow message: communication between participant objects the axes in a sequence diagram: n n horizontal: which object/participant is acting vertical: time (down -> forward in time) 3

Sequence diag. from use case 4

Sequence diag. from use case 4

Representing objects n squares with object type, optionally preceded by object name and colon

Representing objects n squares with object type, optionally preceded by object name and colon n n write object's name if it clarifies the diagram object's "life line" represented by dashed vert. line 5

Messages between objects n message (method call) indicated by horizontal arrow to other object

Messages between objects n message (method call) indicated by horizontal arrow to other object n n n write message name and arguments above arrow dashed arrow back indicates return different arrowheads for normal / concurrent (asynchronous) methods 6

Lifetime of objects n creation: arrow with 'new' written above it n n notice

Lifetime of objects n creation: arrow with 'new' written above it n n notice that an object created after the start of the scenario appears lower than the others deletion: an X at bottom of object's lifeline n Java doesn't explicitly delete objects; they fall out of scope and are garbage-collected 7

Indicating method calls n activation: thick box over object's life line; drawn when object's

Indicating method calls n activation: thick box over object's life line; drawn when object's method is on the stack n n either that object is running its code, or it is on the stack waiting for another object's method to finish nest to indicate recursion Activation Nesting 8

Indicating selection and loops n frame: box around part of a sequence diagram to

Indicating selection and loops n frame: box around part of a sequence diagram to indicate selection or loop n n n if -> (opt) [condition] if/else -> (alt) [condition], separated by horiz. dashed line loop -> (loop) [condition or items to loop over] opt [balance <>0] alt [balance < 100. 00] [balance>= 100. 00] loop [balance < 0] 9

linking sequence diagrams n if one sequence diagram is too large or refers to

linking sequence diagrams n if one sequence diagram is too large or refers to another diagram, indicate it with either: n n n an unfinished arrow and comment a "ref" frame that names the other diagram when would this occur in our system? 10

Example sequence diagram 11

Example sequence diagram 11

Flawed sequence diagram 1 n What's wrong with this sequence diagram? (Look at the

Flawed sequence diagram 1 n What's wrong with this sequence diagram? (Look at the UML syntax and the viability of the scenario. ) 13

Flawed sequence diagram 2 n What's wrong with this sequence diagram? 14

Flawed sequence diagram 2 n What's wrong with this sequence diagram? 14

Flawed sequence diagram 3 n What's wrong with this sequence diagram? : Computer :

Flawed sequence diagram 3 n What's wrong with this sequence diagram? : Computer : Print. Server print(file) : Printer : Queue [if printer free] print(file) [else] enqueue(file) 15

Why not just code it? n Sequence diagrams can be somewhat close to the

Why not just code it? n Sequence diagrams can be somewhat close to the code level. So why not just code up that algorithm rather than drawing it as a sequence diagram? n n n a good sequence diagram is still a bit above the level of the real code (not EVERY line of code is drawn on diagram) sequence diagrams are language-agnostic (can be implemented in many different languages non-coders can do sequence diagrams easier to do sequence diagrams as a team can see many objects/classes at a time on same page (visual bandwidth) 16

Sequence diagram exercise 1 n Let's do a sequence diagram for the following casual

Sequence diagram exercise 1 n Let's do a sequence diagram for the following casual use case, Start New Poker Round : The scenario begins when the player chooses to start a new round in the UI. The UI asks whether any new players want to join the round; if so, the new players are added using the UI. All players' hands are emptied into the deck, which is then shuffled. The player left of the dealer supplies an ante bet of the proper amount. Next each player is dealt a hand of two cards from the deck in a round-robin fashion; one card to each player, then the second card. If the player left of the dealer doesn't have enough money to ante, he/she is removed from the game, and the next player supplies the ante. If that player also cannot afford the ante, this cycle continues until such a player is found or all players are removed. 17

Sequence diagram exercise 2 n Let's do a sequence diagram for the following casual

Sequence diagram exercise 2 n Let's do a sequence diagram for the following casual use case, Add Calendar Appointment : The scenario begins when the user chooses to add a new appointment in the UI. The UI notices which part of the calendar is active and pops up an Add Appointment window for that date and time. The user enters the necessary information about the appointment's name, location, start and end times. The UI will prevent the user from entering an appointment that has invalid information, such as an empty name or negative duration. The calendar records the new appointment in the user's list of appointments. Any reminder selected by the user is added to the list of reminders. If the user already has an appointment at that time, the user is shown a warning message and asked to choose an available time or replace the previous appointment. If the user enters an appointment with the same name and duration as an existing group meeting, the calendar asks the user whether he/she intended to join that group meeting instead. If so, the user is added to that group meeting's list of participants. 18

Data Flow Diagrams

Data Flow Diagrams

Where do they fit in? n n n Life Cycle Phases Planning Feasibility Study

Where do they fit in? n n n Life Cycle Phases Planning Feasibility Study Analysis Design Code and Unit test n Analysis (What do we do? ) n Fact finding n n n investigate business process and the current system modelling the current and required systems deliverables n n requirements specification logical models of the required system

Data Flow Diagrams (DFD) n DFDs describe the flow of data or information into

Data Flow Diagrams (DFD) n DFDs describe the flow of data or information into and out of a system n n what does the system do to the data? A DFD is a graphic representation of the flow of data or information through a system 3

4 Main Elements n n external entity - people or organisations that send data

4 Main Elements n n external entity - people or organisations that send data into the system or receive data from the system process - models what happens to the data i. e. transforms incoming data into outgoing data store - represents permanent data that is used by the system data flow - models the actual flow of the data between the other elements

Notation Data Flow • Data Flow Process box • Process External Entity • External

Notation Data Flow • Data Flow Process box • Process External Entity • External Entity • Data Store D Data Store

Levelled DFDs n Even a small system could have many processes and data flows

Levelled DFDs n Even a small system could have many processes and data flows and DFD could be large and messy n n use levelled DFDs - view system at different levels of detail one overview and many progressively greater detailed views 4

Level 0 - Context Diagram n n n models system as one process box

Level 0 - Context Diagram n n n models system as one process box which represents scope of the system identifies external entities and related inputs and outputs Additional notation - system box

Level 1 - overview diagram n n gives overview of full system identifies major

Level 1 - overview diagram n n gives overview of full system identifies major processes and data flows between them identifies data stores that are used by the major processes boundary of level 1 is the context diagram

Level 2 - detailed diagram n n n level 1 process is expanded into

Level 2 - detailed diagram n n n level 1 process is expanded into more detail each process in level 1 is decomposed to show its constituent processes boundary of level 2 is the level 1 process

Other Notation n n Duplicates marked by diagonal line in corner System Boundary Elementary

Other Notation n n Duplicates marked by diagonal line in corner System Boundary Elementary Processes - star in corner Process that is levelled - dots on top

Rules for DFDs n Numbering n Labelling n Balancing 5

Rules for DFDs n Numbering n Labelling n Balancing 5

Numbering n n On level 1 processes are numbered 1, 2, 3… On level

Numbering n n On level 1 processes are numbered 1, 2, 3… On level 2 processes are numbered x. 1, x. 2, x. 3… where x is the number of the parent level 1 process Number is used to uniquely identify process not to represent any order of processing Data store numbers usually D 1, D 2, D 3. . .

Labelling n n Process label - short description of what the process does, e.

Labelling n n Process label - short description of what the process does, e. G. Price order Data flow label - noun representing the data flowing through it e. G. Customer payment Data store label - describes the type of data stored Make labels as meaningful as possible

Balancing and data stores n Balancing n n any data flows entering or leaving

Balancing and data stores n Balancing n n any data flows entering or leaving a parent level must by equivalent to those on the child level Data stores n data stores that are local to a process need not be included until the process is expanded

Data Flows n n Allowed to combine several data flows from lower level diagrams

Data Flows n n Allowed to combine several data flows from lower level diagrams at a higher level under one data flow to reduce clutter Flows should be labelled except when data to or from a data store consists of all items in the data store

Joe’s Yard Joe’s builders’ suppliers has a shop and a yard. His system is

Joe’s Yard Joe’s builders’ suppliers has a shop and a yard. His system is entirely manual. He has a stock list on the wall of his shop, complete with prices. When a builder wants to buy supplies, he goes into the shop and picks the stock items from the list. He writes his order on a duplicate docket and pays Joe, who stamps the docket as paid. The builder takes the duplicate docket and he goes to the yard and hands it to the yard foreman. The yard foreman gets the ordered items from the yard and gives them to the builder. The builder signs the duplicate docket and leaves one copy with the foreman and takes one copy as a receipt. Every week, Joe looks around the yard to see if any of his stock is running low. He rings up the relevant suppliers and reorders stock. He records the order in his order book, which is kept in the yard. The yard foreman takes delivery of the new stock and checks it against what has been ordered. He pays for it on delivery and staples the receipt into the order book. At the end of every month, Joe goes through all the dockets and the order book and produces a financial report for the shareholders. Draw a context level DFD and a level-1 DFD for this system.

Context Diagram n Find the people who send data into the system n n

Context Diagram n Find the people who send data into the system n n n Often data is part of a PHYSICAL transaction When handing a bar of chocolate to a shopkeeper, you are handing him/her a barcode. Find the people who get data out of the system. n The only data you need is data that is transformed or sent completely out of the system – not data that is handled by an operator within the system.

Joe’s Yard Joe’s builders’ suppliers has a shop and a yard. His system is

Joe’s Yard Joe’s builders’ suppliers has a shop and a yard. His system is entirely manual. He has a stock list on the wall of his shop, complete with prices. When a builder wants to buy supplies, he goes into the shop and picks the stock items from the list. He writes his order on a duplicate docket and pays Joe, who stamps the docket as paid. The builder takes the duplicate docket and he goes to the yard and hands it to the yard foreman. The yard foreman gets the ordered items from the yard and gives them to the builder. The builder signs the duplicate docket and leaves one copy with the foreman and takes one copy as a receipt. Every week, Joe looks around the yard to see if any of his stock is running low. He rings up the relevant suppliers and reorders stock. He records the order in his order book, which is kept in the yard. The yard foreman takes delivery of the new stock and checks it against what has been ordered. He pays for it on delivery and staples the receipt into the order book. At the end of every month, Joe goes through all the dockets and the order book and produces a financial report for the shareholders. Draw a context level DFD and a level-1 DFD for this system.

Context diagram

Context diagram

Level-1 DFD processes Joe’s builders’ suppliers has a shop and a yard. His system

Level-1 DFD processes Joe’s builders’ suppliers has a shop and a yard. His system is entirely manual. He has a stock list on the wall of his shop, complete with prices. When a builder wants to buy supplies, he goes into the shop and picks the stock items from the list. He writes his order on a duplicate docket and pays Joe, who stamps the docket as paid. The builder takes the duplicate docket and he goes to the yard and hands it to the yard foreman. The yard foreman gets the ordered items from the yard and gives them to the builder. The builder signs the duplicate docket and leaves one copy with the foreman and takes one copy as a receipt. Every week, Joe looks around the yard to see if any of his stock is running low. He rings up the relevant suppliers and reorders stock. He records the order in his order book, which is kept in the yard. The yard foreman takes delivery of the new stock and checks it against what has been ordered. He pays for it on delivery and staples the receipt into the order book. At the end of every month, Joe goes through all the dockets and the order book and produces a financial report for the shareholders.

Verbs from script n n n n n Has (passive) Buy supplies Picks stock

Verbs from script n n n n n Has (passive) Buy supplies Picks stock items Writes order Pays joe Stamps docket Takes docket to yard Hands it to foreman Gets items Gives them to builder n n n n Builder signs docket Takes copy as receipt Looks around yard and reorders Records order in order book Foreman takes delivery – checks Foreman pays supplier Staples receipt to order book Produces financial report

Remove passive verbs and queries n Joe then n Passive: has stock list Buy

Remove passive verbs and queries n Joe then n Passive: has stock list Buy supplies n n n Customer then n Picks stock items (views list) Writes orders Pays joe Stamps docket Takes docket to yard Hands it to foreman Gets items n n n Gives them to builder Builder signs docket Takes copy as receipt n n Foreman n n Looks around yard and reorders Records order in order book takes delivery – checks Foreman pays supplier Staples receipt to order book Joe n Produces financial report

Level 1 current physical

Level 1 current physical

Buy Supplies

Buy Supplies

Get Items

Get Items

Reorder supplies

Reorder supplies

Restock

Restock