Sequence Diagrams and Collaboration DiagramsIntroduction/AgendaObject Oriented DesignSequence DiagramSequence Diagram - ObjectsSequence Diagram – Time & MessagesTypes of MessagesSequence Diagram – CompilationBranching Flow: flow goes to different objects [if condition is met]Alternative Flow: flow changes to alternative lifeline branch of the same objectSequence diagram -exampleSystem Design PrinciplesReading from a command file - exampleSequence Diagram – URS Add Subject ScenarioCreating and Deleting objectsCollaboration DiagramsCollaboration DiagramsCollaboration Diagram – URS Add Subject ScenarioSlide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25URS -High Level Class DiagramSlide 27Use Case Vs ScenariosSequence Diagram – Enroll Student for subject successfullyCollaboration Diagram – Enroll Student in Subject ScenarioCollaboration Diagram – Enroll Student in Subject subject - implementationSequence Diagram – Enroll Student for subject - Failure1Sequence Diagramsand Collaboration Diagrams Rajkumar BuyyaGrid Computing and Distributed Systems (GRIDS) LaboratoryDept. of Computer Science and Software EngineeringUniversity of Melbourne, Australiahttp://www.cs.mu.oz.au/~raj or http://www.buyya.com2Introduction/AgendaPieces of UML:Structural DiagramsClass and object diagramComponent and Deployment DiagramBehavioural Diagrams Use Case DiagramActivity DiagramSequence DiagramCollaboration DiagramState Chart DiagramLearned so far: Use case diagram, class and object diagram, class relationshipsToday we will focus on:Sequence DiagramCollaboration Diagram3Object Oriented DesignDesign consists of the following steps :Refine the class diagram.Draw the interaction diagrams for the system.Sequence DiagramCollaboration DiagramIf objects go through complex state transitions – statechart diagramsDo the above steps iteratively as needed.4Sequence DiagramShows how objects communicate with each other over time.That is, sequence diagrams are used to model object interactions arranged in time sequence and to distribute use case behavior to classes.They can also be used to illustrate all the paths a particular use case can ultimately produce.The sequence diagram consists of Active Objects, Messages represented as solid-line arrows, and Time represented as a vertical progression.5Sequence Diagram - ObjectsA life line illustrates what is happening to an object in a chronological fashion.:NameLife lineActivationObject6Sequence Diagram – Time & MessagesMessages are used to illustrate communication between different active objects of a sequence diagram.:Name1 :Name2Message TwoActorMessage One7Types of MessagesSynchronous (flow interrupt until the message has completed.Asynchronous (don’t wait for response)Flat – no distinction between sysn/asyncReturn – control flow has returned to the caller.8Sequence Diagram – Compilation:Compiler LinkerActorCompileFileSystemLoad FilesSave OBJ FilesCompile filesLinkLoad OBJ filesLink OBJ filesWrite EXE file9Branching Flow: flow goes to different objects [if condition is met]:Editor FileSystemLoad File:BinaryViewer :TextViewer[text file][binary file]10Alternative Flow: flow changes to alternative lifeline branch of the same objectEditorActorExit AppFileSystem[delete file][save file]11Sequence diagram -exampleUse case Add Subject Use Case to URS (University Record System):ScenarioScenario 1 : Subject gets added successfully.Scenario 2 : Adding the subject fails because the subject is already in the database.12System Design PrinciplesSystem input can take different forms. E.g.From a graphical user interfaceFrom a command fileURS system should be designed such that the functionality can be re-used.Command reading and functionality implementation have to be separated.13Reading from a command file - exampleclass URS{ public static void main(String[] args){ URSDatabase u = new URSDatabase(); //Read command from file; while ( not end of file) {u.procCommand(cmd);//Read next commad;}//Close file}}14execute()Sequence Diagram – URS Add Subject Scenariou:URSDatabaseprocCmd(cmd)sub1:SubjectSubject(id,name)<< create >>parseCommand(cmd)addSubject(sub1){transient}a:AddSubCmd << create >>[if cmdN = ADDSUB]AddSubCmd(u,cmdA)15Creating and Deleting objectsc:Client:Transactionp: ODBProxysetVales(a,d,3,4)<<destroy>><<create>>committedsetAction(a, d, 0){transient}16Collaboration Diagrams17Collaboration DiagramsClass diagrams indicates what classes are part of our system, what they offer, how they relate, but they don’t tell us how they communicate.Collaboration diagrams show (used to model) how objects interact and their roles.They are very similar to sequence diagrams. Actually they are considered as a cross between class and sequence diagram.Sequence Diagrams are arranged according to Time.Collaboration Diagrams represent the structural organization of object.[Both sequence and collaboration diagrams are called interaction diagrams]18Collaboration Diagram – URS Add Subject Scenariou:URSDatabase<<self>>a:AddSubCmd 2:[if cmdN = ADDSUB]AddSubCmd(u,cmdA) <<local>>{new}{transient}3: execute()3.2: addSubject(sub1)1:parseCommand(cmd)procCmd(cmd)sub1:Subject 3.1: Subject(id,name){new}19Collaboration Diagram – URS Add Subject Scenariou:URSDatabase<<self>>1:parseCommand(cmd)procCommand(cmd)class URSDatabase{ private String cmdN; private String cmdA; private parseCommand(String cmd){ cmdN = …. cmdA = …. } public procCommand(String cmd){ parseCommand(cmd); }}20Collaboration Diagram – URS Add Subject Scenariou:URSDatabasea:AddSubCmd 2: AddSubCmd(u,cmdA){new}{transient}class URSDatabase{ private String cmdN; private String cmdA; public procCommand(String cmd){ parseCommand(cmd); if (cmdN == ADDSUB){ AddSubCmd a = new AddSubCmd(u,cmdA); } }}21Collaboration Diagram – URS Add Subject Scenarioclass abstract Command { protected String cmd; protected URSDatabase u; public abstract void execute();} class AddSubCmd extends Command{ public AddSubCmd(URSDatabase urs, String cmd){ u = urs; // parse command and set the arguments } public void execute(){ // implement here }}22Collaboration Diagram – URS Add Subject Scenariou:URSDatabasea:AddSubCmd<<local>>3: execute()class URSDatabase{ private String cmd; public
View Full Document