缺省適配模式為一個接口提供缺省實(shí)現(xiàn),這樣子類型從這個缺省實(shí)現(xiàn)進(jìn)行擴(kuò)展時,就不必實(shí)現(xiàn)原有接口的所有方法了。
應(yīng)用:
windowslistener借口定義如下:
jdk WindowListener提供了一個WindowListener的默認(rèn)實(shí)現(xiàn)類WindowAdapter類,這是一個抽象類,
應(yīng)用:
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);
}
要實(shí)現(xiàn)這個接口,我們就必須實(shí)現(xiàn)它所定義的所有方法,但是實(shí)際上,我們很少需要同時用到所有的方法,我們要的只是其中的兩三個。為了不使我們實(shí)現(xiàn)多余的方法,
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的默認(rèn)實(shí)現(xiàn)類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){}
}
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){}
}