接口(适配器)
package workhome; public class WindowDemo { public static void main(String[] args) { //匿名内部类对象,方法链编程 new Window().addListener(new WindowAdapter() { public void max() { System.out.println("窗口最大化"); } public void min() { System.out.println("窗口最小化"); } }).winMax() .winMin(); } } interface WindowListener{ public void max(); public void min(); public void resize(); public void restore(); public void move(); public void close(); } //适配器 abstract class WindowAdapter implements WindowListener{ public void max(){} public void min(){} public void resize(){} public void restore(){} public void move(){} public void close(){} } class Window{ private WindowListener l; public Window addListener(WindowListener l) { this.l=l; return this; } public Window winMax() { l.max(); return this; } public void winMin() { l.min(); } }