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
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
Method's execution timeline
Lifelines
Method Calls
Objects alive throughout the execution
public class RegistrationSystem {
private List<Student> students;
public void printRecords() {
for (Student s : students) {
Rec rec = s.getRec();
// ...
}
}
}
Loop box
Same for conditionals!
if: ...
else if: ...
else: ...
Note: exact notation may differ between variations
public class Street {
public static void main(String[] args) {
Magician magician = new Magician();
Onlooker carl = new Onlooker();
magician.attractAudience(carl);
magician.doMagicTrick();
}
}
public class Magician {
private Onlooker audienceMember = null;
public void doMagicTrick() {
audienceMember.beAmazed();
}
public void attractAudience(Onlooker a) {
audienceMember = a;
}
}
public class Onlooker {
public void beAmazed() {
gasp();
}
private void gasp() {
}
}
Magician
magician
Onlooker
carl
beAmazed()
doMagicTrick()
gasp()
Recommended procedure:
@Override
public void printLog(EventLog el) {
for (Event next : el) {
logArea.setText(logArea.getText() + next.toString() + "\n\n");
}
repaint();
}
@Override
public void printLog(EventLog el) {
for (Event next : el) {
logArea.setText(logArea.getText() + next.toString() + "\n\n");
}
repaint();
}
Text