Interfaces as callbacks
I'm reading through O'Reilly's Learning Java and I'm having trouble wrapping my brain around this concept. Here's the example code they give.
I understand the basic concept of Interfaces, specifying defined behavior through a group of abstract classes.
Can someone explain to me what's going on here?
interface TextUpdateable {
void doTextUpdate( String text);
}
class TickerTape implements TextUpdateable {
public void doTextUpdate(String text) {
System.out.println("TICKER:\n" + text + "\n");
}
}
class TextSource {
TextUpdateable receiver;
TextSource(TextUpdateable r) {
receiver = r;
}
public void sendText( String s) {
receiver.doTextUpdate(s);
}
}
I understand the basic concept of Interfaces, specifying defined behavior through a group of abstract classes.
Can someone explain to me what's going on here?
