13. 프록시 모드(Proxy Pattern)

4084 단어 Pattern
using System;



namespace ConsoleApplication6

{

    class Program

    {

        static void Main(string[] args)

        {

            //                          

            Person proxy = new Friend();            

            proxy.BuyProduct();            

            Console.Read();

        }

    }



    //       

    public abstract class Person

    {

        public abstract void BuyProduct();

    }



    //    

    public class RealBuyPerson : Person

    {

        public override void BuyProduct()

        {

            Console.WriteLine("       IPhone       ");

        }

    }



    //     

    public class Friend : Person

    {

        RealBuyPerson realSubject;



        public override void BuyProduct()

        {      

            if (realSubject == null)

            {

                realSubject = new RealBuyPerson();

            }



            realSubject.BuyProduct();

            Console.WriteLine("          ");

            this.PreBuyProduct();     

            this.PostBuyProduct();

        }



        public void PreBuyProduct()

        {

            Console.WriteLine("      IPhone       ");      

        }



        public void PostBuyProduct()

        {

            Console.WriteLine("    IPhone             ");

        }

    }



 

}

좋은 웹페이지 즐겨찾기