1.回调(CallBack)或在C语言中叫做钩子函数(Hook)也叫做:模板方法模式
代码实现:
代码1
------------------------------------------------------------
package edu.neuq.oop.callback;
import java.awt.Frame;
public class PaintFrame {
public static void drawFrame(MyFrame f){
System.out.println("启动线程");
System.out.println("增加循环");
System.out.println("查看消息栈");
f.paint();//画窗口 此处即为钩子函数,通过多态的概念可以实现画各种子 类窗口
System.out.println("启动缓存,增加效率");
}
public static void main(String[] args){
drawFrame(new GameFrame02());
}
}
class GameFrame01 extends MyFrame{
public void paint(){
System.out.println("GameFrame01.paint()");
System.out.println("画窗口");
}
}
class GameFrame02 extends MyFrame{
public void paint(){
System.out.println("GameFrame02.paint()");
System.out.println("画窗口");
}
}
代码2
--------------------------------------------------------------------------
package edu.neuq.oop.callback;
import java.awt.Graphics;
public class MyFrame {
public void paint(){
System.out.println("画出我的窗口");
}
}
---------------------------------------------------------------