Task : To implement a call-back facility

Untitled


public class Myclass{
	public void f(){
		...
		Timer t = new Timer(this);  // Timer t should know who to notify. Myclass m passes its identity when it creates a Timer.
		...
		t.start();
		...
	}
	public void timerdone() { ... }
}
public class Timer implements Runnable{
	//Now timer can be invoked in parallel
		private Myclass owner; //instance variable

	public Timer(Myclass o){
		owner = o;
	}

	public void start(){
		...
		owner.timerdone();
	}
}

Here the Timer is specific to Myclass .


Generic Timer


Use interfaces