Ejemplo n.º 1
0
        void Start()
        {
            Printable p = new PrinterProxy("Alice");

            Debug.Log("名前は現在" + p.GetPrinterName() + "です。");
            p.SetPrinterName("Bob");
            Debug.Log("名前は現在" + p.GetPrinterName() + "です");
            p.Print("Hello, world");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("ProxyPattern");
            IPrintable proxy = new PrinterProxy("Alice");

            WriteLine($"现在的名字是{proxy.GetPrinterName()}.");

            proxy.SetPrinterName("Bob");

            WriteLine($"现在的名字是{proxy.GetPrinterName()}.");

            proxy.Print("Hello World!");

            //只有需要调用Print的时候才生成Printer的实例,
            //在调用Print之前(生成实例之前) 可以调用代理的其他方法,间接模拟调用尚未初始化的Printer中的其他方法
            ReadKey();
        }