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();
    
        }
    }
    
  • 相关阅读:
    实验 1:Mininet 源码安装和可视化拓扑工具
    ORACLE 数据库异常关闭处理办法
    Tomcat安装及配置教程
    关于Eclipse无server选项的解决方法
    2020软件工程作业02
    2020软件工程作业01
    C语言II作业01
    C语言总体概览
    C语言寒假大作战04
    C语言寒假大作战03
  • 原文地址:https://www.cnblogs.com/kfx2007/p/2793391.html
Copyright © 2011-2022 走看看