270 likes | 401 Views
CS12420 Sequence Diagrams – a UML notation for modelling bahaviour. Lynda Thomas ltt@aber.ac.uk. Images from Wikipedia unless credited or mine. Current UML - recap. Class diagrams tell you: the static structure of the system the relationships between the data
E N D
CS12420Sequence Diagrams – a UML notation for modelling bahaviour Lynda Thomas ltt@aber.ac.uk Images from Wikipedia unless credited or mine
Current UML - recap • Class diagrams tell you: • the static structure of the system • the relationships between the data • the methods give clues to what can happen • Object diagrams tell you: • A snapshot of how the system might look at some point in time
Class Diagram Object Diagram
How do you model what happens in a software system? Use Case diagram tells you: • Who the actors are in the system • What they can do This is really an analysis diagram
But that doesn’t tell you design i.e. in what order things happen or how to write the methods
Sequence diagrams do that • Let’s use google • http://en.wikipedia.org/wiki/Sequence_diagrams • http://www.ibm.com/developerworks/rational/library/3101.html • http://www.agilemodeling.com/artifacts/sequenceDiagram.htm
T I M E
So the basic idea is that it shows ‘what happens when’ • Phone Example is ‘above’ the specific design level of a program – more like analysis • Sequence Diagrams can be at any level actually – analysis or design and help you ‘get your head around’ what is happening • Consider the procedure for applying to university through UCAS – let’s try it
But usually used to look at how objects in an OO system interactLet’s have a look at the .pdf filehttp://csis.pace.edu/~marchese/CS389/L9/Sequence%20Diagram%20Tutorial.pdffor the syntax
Cute (but just noticed error) - Three Little Pigs http://www.tracemodeler.com/articles/pimp-my-diagram-three-little-pigs/index.html?src=rss
Why not just code it? • Sequence diagrams describe single use cases showing the behaviour across objects of many classes • can see many objects/classes at a time on same page • good sequence diagram is still a bit above the level of the real code • can be implemented in many different languages • non-coders can do sequence diagrams • easier to do sequence diagrams as a team
An example CS122 exam: The translation unit. Ordinary users of the unit can look up Welsh and English words and phrases and get their translation. They can also submit documents for translation (in the direction Welsh to English or English to Welsh) and find out whether those translations are complete, in process or not started……. Let’s add a new functional requirement: Users can submit and get an emergency translation of a document
0..* -dictionary Application //runs menu Model //holds data 1..1 LinguisticUnit //a word or phrase 0..* +emerTrans (): void +doEmerTrans (): void 0..* -allDocs 0..* -translators DocumentInfo//information about document +DocumentInfo(String docName, String whichDirection, String uid, Date dateSubmitted) + String getDocName() + void setCheckedOut(Translator translator) +Translator getTranslator() + void setCompleted() + boolean isCompleted() + Date getDate() + String toString() Translator //stores all info -String uid -String phone 0..* -myDocs 0..1-trans
0..* -dictionary Application //runs menu Model //holds data 1..1 LinguisticUnit //a word or phrase 0..* +emerTrans (): void +doEmerTrans (): void +getFreeTrans (): Translator 0..* -allDocs 0..* -translators DocumentInfo//information about document +DocumentInfo(String docName, String whichDirection, String uid, Date dateSubmitted) + String getDocName() + void setCheckedOut(Translator translator) +Translator getTranslator() + void setCompleted() + boolean isCompleted() + Date getDate() + String toString() Translator //stores all info -String uid -String phone 0..* -myDocs 0..1-trans
0..* -dictionary Application //runs menu Model //holds data 1..1 LinguisticUnit //a word or phrase 0..* +emerTrans (): void +doEmerTrans (): void +getFreeTrans (): Translator 0..* -allDocs 0..* -translators DocumentInfo//information about document +DocumentInfo(String docName, String whichDirection, String uid, Date dateSubmitted) + String getDocName() + void setCheckedOut(Translator translator) +Translator getTranslator() + void setCompleted() + boolean isCompleted() + Date getDate() + String toString() Translator //stores all info -String uid -String phone 0..* -myDocs 0..1-trans +doEmer(DocInfo d): void
Alternatives? Interaction diagrams do the same sort of job Take an object diagram and draw numbered arrows I think they are harder to understand but easier to write
Pseudocode can be used at any level (code w/out syntax) Higher Level: (doEmerTrans() of Model) aDoc=new DocInfo(…) aTrans= freetranslator() checkout aDoc to aTrans aDoc.setCompleted() Detailed: Initialize total to zero Initialize counter to zero Input the first grade while user has not as yet entered the sentinel add this grade into the running total add one to the grade counter input the next grade (possibly the sentinel) if the counter is not equal to zero set the average to total /counter print the average else print 'no grades were entered' That tells me that I need to look further at freetranslator() (easy)and at checkout() … Decide to use setCheckedout(aTrans) in DocInfo … here is pseudocode translator=aTrans translator.doEmer() Now need to elaborate doEmer() in Translator
State diagrams look at the internals of an object – more next year Here is a vending machine
Flow charts don’t work as well with objects but can be useful for detailed logic
There are tools for this • Tools to help produce them • Tools to produce code from them • Tools to take code and produce diagrams
What do I honestly use to design? • Start usually with a rough use case diagram • then a very messy object diagram • then a rough class diagram • then I pick a use case and using my pen move around the object diagram being sure I can do that use case (bit like interaction diagram • usually that involves jotting down some pseudocode, which like on previous gives me more methods for the class diagram and more things to pseudocode – quit when it gets easy
But design is also about communication • What I said on last slide is fine to get started • But …. • You may be working with others • You may not be the one who is maintaining the system • You may forget what you did and why So readable design documentation is needed
Worksheet four • ??