代理模式——代碼版“吊絲的故事”

來源:互聯網
上載者:User
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();    }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.