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();
    
        }
    }
    
  • 相关阅读:
    表单提交:button input submit 的区别
    JavaScript中改变this指针的注意事项
    宝塔服务器配置nginx刷新404的问题汇总
    ES6笔记整理
    axios网络请求
    v-model双向绑定
    v-bind动态绑定
    前端模块化
    vue router 路由
    JS高阶函数
  • 原文地址:https://www.cnblogs.com/kfx2007/p/2793391.html
Copyright © 2011-2022 走看看