| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
//代理设计模式 
//********************************************************* 
interface Ieat 
{ 
        public abstract void get(); 
} 
//*************************************************** 
class EatReal implements Ieat  
{ 
        public void get() 
        { 
                System.out.println("EatReal类==>get()方法"); 
        } 
} 
//*************************************************** 
class EatProxy implements Ieat 
{ 
        private Ieat eat; 
        public EatProxy(Ieat eat) 
        { 
                this.eat=eat; 
        } 
        public void prepare() 
        { 
                System.out.println("EatProxy类==>prepare()方法"); 
        } 
        public void clear() 
        { 
                System.out.println("EatProxy类==>clear()方法"); 
        } 
        public void get()                //覆写get()方法 
        { 
                this.prepare(); 
                this.eat.get();                //输出是EatReal类中的get()方法?????????? 
        } 
} 
//********************************************* 
public class InterfaceDemo_0914_2400 
{ 
        public static void main(String[] args) 
        { 
        Ieat eat=new EatProxy(new EatReal()); 
        eat.get(); 
        } 
} |   
 
 
 
 |