Java_50_ callback implementation _ template method pattern

callback implementation

CallBack

Hook

----------------------------------------------------

public class Test {//parent classpublic void paint() { System.out.println("Create a window"); } }

----------------------------------------------------

public class CallBackTest { Public static void drawFrame(Test x) { System.out.println("Start the first item"); System.out.println("Start second item"); System.out.println("Start third item"); X.paint();// callback methodSystem.out.println("end"); } Public static void main(String[] args) { CallBackTest.drawFrame(new GameFrame());//CallBackTest.paint(Test x) actually uses polymorphism x=new GameFrame()} } Class GameFrame extends Test{//Subclass inherits the parent class and overrides the paint methodpublic void paint() { System.out.println("Create a game window"); } }

----------------------------------------------------