luyantl 发表于 2018-9-15 00:18:58

InterfaceDemo_0914_2400

//代理设计模式
//*********************************************************
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();
        }
}
页: [1]
查看完整版本: InterfaceDemo_0914_2400