下面给出回调的模型和另一个实例以便我们更好的学习

/*
 * Java里面的接口回调,简单的情况示意如下
 */
interface A {}
 
class B implements A {}
 
class C implements A {}
 
class Test {
    A b = new B();
    A c = new C();
}

/*
 * 考虑这样一个应用: NameChanger动态地改变Client的名字
 * 那NameChanger的changeName方法要接收一个Client对象,然后获取(调用)Client的名字并作不同的处理
 * Client也要持有NameChanger,因为要打印改变后的名字
 */
class Client {
 
    private INameChanger changer;
    private String clientName;
    
 
    public Client(INameChanger changer) {
        this.changer = changer;
    }
 
    public void showMyNewName() {
        String newName = changer.changeName(Client.this);
        System.out.println(newName);
    }
    
    public String getName() {
        return clientName;
    }
 
    public void setName(String clientName) {
        this.clientName = clientName;
    }
}
 
 interface INameChanger {
    
    public String changeName(Client client);
    
}
 
 
public class ChangeNameTest {
    
    public static void main(String[] args) {
        
        Client client = new Client(new INameChanger(){
            public String changeName(Client client) {
                return "Mr." + client.getName();
            }
        });
        client.setName("Tom");
        client.showMyNewName();
        
        Client client2 = new Client(new INameChanger(){
            public String changeName(Client client) {
                return "Miss." + client.getName();
            }
        });
        client2.setName("Lucy");
        client2.showMyNewName();
        
    }