缺省适配模式为一个接口提供缺省实现,这样子类型从这个缺省实现进行扩展时,就不必实现原有接口的所有方法了。
应用:
windowslistener借口定义如下:
public interface WindowListener extends EventListener{
public void windowActivated(WindowEvent e);
public void windowClosed(WindowEvent e);
public void windowClosing(WindowEvent e);
public void windowDeactivated(WindowEvent e);
public void windowDeiconified(WindowEvent e);
public void windowIconified(WindowEvent e);
public void windowOpened(WindowEvent e);
}
要实现这个接口,我们就必须实现它所定义的所有方法,但是实际上,我们很少需要同时用到所有的方法,我们要的只是其中的两三个。为了不使我们实现多余的方法,
jdk WindowListener提供了一个WindowListener的默认实现类WindowAdapter类,这是一个抽象类,
public abstract class WindowAdapter implements WindowListener{
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowClosing(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
}