/**
*
*/
package cm.interfaces.factory;
/**
* @author 彦舜
*
*/
public class ModelFsixtyNine {
/**
*
*/
public ModelFsixtyNine() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
Network net = null;
net = new Proxy(new Real());
net.browse();
}
}
//定义network接口
interface Network{
//定义浏览的抽象方法
public void browse();
}
class Real implements Network{
@Override
public void browse() {
System.out.println("Real.browse()");
}
}
class Proxy implements Network{
//Proxy this = new Proxy(); this.network = Proxy.network;
private Network network;
//Proxy this = new Proxy(); this.network = Proxy.network;
public Proxy(Network network) {
network = new Real();
//this.network = Proxy.Network.network2
//Network是接口类,Real是接口子类,即Network network = new Real();
this.network = network;
//Type mismatch: cannot convert from Real to Proxy:同一个等级的两个类之间,无法进行类型转换,不能用一个类去实例化另一个类。故,此处,实例化的是向上或
彦舜原创,CSDN首发:接口代理设计(重要),详解代码原义,思路清晰直观,易于学习,适合有基础的人亦适合初学者
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.