Javase basics callback functions

 

 

1 final :



 

 

 2 interfaces:  

The meaning of the interface is to separate the design and implementation, and the specific details are designed for subsequent people to implement.

Java is suitable for large-scale software, and requires the cooperation of many people before the appearance of the interface.

 

 

3 callback functions :

 

Callback function - hook function:

 

xxxxx

yyyy

---- ?? Not sure how to do it, let others do it, then stick out a hook, others put beef is beef, put pork is pork,

mmmm

zzzz

 

Code:

public abstract class MyFrame {

	public void paint() {
		System.out.println("i am MyFrame");
	}
}




public class PaintFrame {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MyFrame2 myFrame2 = new MyFrame2();
		drawFrame(myFrame2); // the caller decides what type of meat to attach to the hook
		
		/* start the thread
		add loop
		View messages
		from MyFrame2, draw a new bird picture
		start cache */
	}

	
	public static void drawFrame(MyFrame myFrame) {
		System.out.println("Start thread");
		System.out.println("Increase loop");
		System.out.println("View message");
		// The hook is the specific usage scenario of the polypeptide. I don't know how to do it here. I will give the specific method to the caller. The caller attaches beef to the hook, which is beef and pork.
		myFrame.paint();
		
		System.out.println("Start cache");
	}
}

class MyFrame1 extends MyFrame {

	@Override
	public void paint() {
		System.out.println("from MyFrame1, draw a new dog picture");
	}
	
}

class MyFrame2 extends MyFrame {

	@Override
	public void paint() {
		System.out.println("from MyFrame2, draw a new bird picture");
	}
	
}

 

 

 

54 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326447046&siteId=291194637