A Story by Joseph Bergin
The year is 490 BC.
Athens sends an army against Darius the Persian.
She instructs her general, Miltiades: "Let us know immediately if you are successful."
The Athenian army meets Darius' army at Marathon and defeats the Persians decisively.
Miltiades sends a runner, Pheidippides, to Athens to inform the city of the event.
The Athenians rejoice. Pheidippides dies.
Athens sends an army against Darius the Persian.
Athens wishes to perform as a victory handler.
She instructs her general, Miltiades: "Let us know immediately if you are successful."
She registers her intention of handling victory events with the source of such events: Miltiades.
The Athenian army meets Darius' army at Marathon and defeats the Persians decisively.
An event (small "e") occurs. Miltiades must inform all registered victory handlers (just one here).
Miltiades sends a runner, Pheidippides, to Athens to inform the city of the event.
The Victory Event object (capital "E") is sent from the event source to each victory handler.
The Athenians rejoice. Pheidippides dies.
The Victory Event object arrives and the handler executes the victory performed action. The Event object expires.
Athens sends an army against Darius the Persian.
Athens wishes to perform as a victory handler.
City Athens = new City (Greece);
She instructs her general, Miltiades: "Let us know immediately if you are successful."
She registers her intention of handling victory events with the source of such events: Miltiades.
General Miltiades = new General(Athens);
Miltiades.addVictoryHandler(new MarathonHandler(Athens));The Athenian army meets Darius' army at Marathon and defeats the Persians decisively.
An event (small "e") occurs. Miltiades must inform all registered victory handlers (just one here).
class General
{ ...
public void fightBattle(Enemy enemy, Place place, Date date)
{ ...
winBattle(this, enemy, place, date);
}public void winBattle(Enemy enemy, Place place, Date date)
{ ...
notifyVictoryHandlers(new VictoryEvent(this, enemy, place, date));
}public void addVictoryHandler(VictoryHandler h)
{ ...
}
}Miltiades sends a runner, Pheidippides, to Athens to inform the city of the event.
The Victory Event object (capital "E") is sent from the event source to each victory handler.
class MarathonHandler implements VictoryHandler
{ public MarathonHandler(City city)
{ this.city = city;
}public void victoryPerformed(VictoryEvent evt)
{ city.rejoice();
}
private City city = null;
}The Athenians rejoice. Pheidippides dies.
The Victory Event object arrives and the handler executes the victory performed action. The Event object expires.