CPSC 210

C5: Extracting Sequence Diagrams

Learning Goals

  • Extract a sequence diagram from a given Java code base

Sequence Diagrams

  • Depicts the calls between objects while the system is running
    • Vertical timeline of calls from top to bottom
  • Starts with a particular method call
A a = new A();
B b = new B();
a.doA(b);

public class A {
    public void doA(B b) {
        b.doB();
    }
}

public class B {
    public void doB() { }
}
Objects
Method Calls
Execution Timeline
Lifelines

An Object Calling Its Own Methods

A a = new A();
B b = new B();
a.doA(b);

public class A {
    public void doA(B b) {
        b.doB();
    }

public class B {
    public void doB() {
        this.doB2();
    }

    public void doB2() { }
}
Call to same object

Parts of the Diagram (again)

Method's execution timeline

Lifelines

Method Calls

Objects alive throughout the execution

Loops & Conditionals

public class RegistrationSystem {
  private List<Student> students;

  public void printRecords() {
    for (Student s : students) {
      print(s.getRec());
    }
  }
}

Our collection

Loop condition

Loop box

Same for conditionals!

if: ...

else if: ...

else: ...

Real
Example

Note: it's a means of communication! It's not all set in stone!

Lecture Ticket Review

Lecture Lab

Lecture Lab

Recommended procedure:

  • Sketch your objects and lifelines
    • How many lifelines do we need?
  • Sketch your loop/alternation boxes
    • How many loop/alternation boxes do we need?

C5: Extracting Sequence Diagrams

The End - Thank You!

C5 Extracting Sequence Diagrams

By Steven Wolfman

C5 Extracting Sequence Diagrams

  • 217