zoukankan      html  css  js  c++  java
  • 代理模式——代码版“吊丝的故事” Kevin

    namespace ProxyDemo
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                //there is a shyboy's dream girl named xuxiao
                DreamGirl girl = new DreamGirl();
                girl.name = "xuxiao";
    
                //there is a shyboy name kevin kong,he love the girl,but he never said to her that he love her.
                ShyBoy shyBoy = new ShyBoy();
                shyBoy.name = "Kevin Kong";
    
                //once ,he want through he and the dream gril's commen friend,guimeng,to say he like her.
                GoodFriend goodFriend = new GoodFriend(shyBoy, girl);
                goodFriend.SendFlower();
                goodFriend.SendLoveMail();
                goodFriend.SendShortMessage();
    
                //finnally the shyboy never said his love to the girl and he lost her forever.
                
            }
        }
    }
    
    namespace ProxyDemo
    {
        /// <summary>
        /// this is a pretty girl.
        /// </summary>
        class DreamGirl
        {
            public string name { get; set; }
        }
    }
    
    namespace ProxyDemo
    {
        /// <summary>
        /// this boy want to pursuit the pretty girl but he doesn't dare.
        /// </summary>
        class ShyBoy:IPursuitMethod
        {
            public string name;
            public void SendLoveMail()
            {
                MessageBox.Show("Send Love Mail");
            }
    
            public void SendFlower()
            {
                MessageBox.Show("Send Love Flower");
            }
    
            public void SendShortMessage()
            {
                MessageBox.Show("Send Love ShortMessage");
            }
        }
    }
    
    namespace ProxyDemo
    {
        //GM is they commen friend. 
        
        class GoodFriend:IPursuitMethod
        {
            private ShyBoy shyBoy;
            private DreamGirl girl;
    
            public GoodFriend(ShyBoy shyBoy,DreamGirl girl)
            {
                this.shyBoy = shyBoy;
                this.girl = girl;
            }
    
            public void SendLoveMail()
            {
                MessageBox.Show("Send Love Mail to "+girl.name+" for "+shyBoy.name);
            }
    
            public void SendFlower()
            {
                MessageBox.Show("Send Love Flower to " + girl.name + " for " + shyBoy.name);
            }
    
            public void SendShortMessage()
            {
                MessageBox.Show("Send Love Message to " + girl.name + " for " + shyBoy.name);
            }
        }
    }
    
    namespace ProxyDemo
    {
        /// <summary>
        /// guys using those mothed to pursuit the pretty girl.
        /// </summary>
        interface IPursuitMethod
        {
             void SendLoveMail();
    
             void SendFlower();
    
             void SendShortMessage();
    
        }
    }
    
  • 相关阅读:
    【luogu2756】 飞行员配对方案问题 [二分图匹配 匈牙利算法]
    [APIO2008]紧急集合
    2019.8.27 Za
    【luogu2763】试题库问题 [网络流 最大流]
    [CQOI2014]危桥 [网络流 最大流]
    【luogu1231】教辅的组成 [网络流 最大流]
    【网络流】
    【2019.8.24】
    【匈牙利算法】
    2019.8.23 Za [数论]
  • 原文地址:https://www.cnblogs.com/kfx2007/p/2793391.html
Copyright © 2011-2022 走看看