C # bridge Mode (bridge structure mode ),

Source: Internet
Author: User

C # bridge Mode (bridge structure mode ),

Bridge Mode c # simple example

Each action added to the previous player must be added to each player. The action is extracted in the bridging mode to reduce changes.

?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms; namespace adapterpattern{    public partial class bridge : Form    {        public bridge()        {            InitializeComponent();        }         private void btnDisplay_Click(object sender, EventArgs e)        {            play p1 = new play1();            p1.setPlayAction(new move());            p1.run();            this.listBox1.Items.Add(p1.playstring);            play p2 = new play2();            p2.setPlayAction(new jump());            p2.run();            this.listBox1.Items.Add(p2.playstring);        }    }    // Intent separates the abstract part from the implementation part so that they can all change independently.    public abstract class play// Abstract Part    {        public string playstring { get; set; }        protected playAction pa;        public void setPlayAction(playAction pa)// Combination        {            this.pa = pa;        }        public abstract void action();// Abstract partial changes        public void run()        {            pa.action();// Implementation            action();        }    }    public class play1 : play    {        public override void action()        {            playstring = "play1" + pa.actionstring;        }    }    public class play2 : play    {        public override void action()        {            playstring = "play2" + pa.actionstring;         }    }    public abstract class playAction// Abstract The implementation Part    {        public string actionstring;        public abstract void action();    }    public class move : playAction// Implement gamer Movement    {        public override void action()        {            actionstring = "move";        }    }    public class jump : playAction// Implements player jumping    {        public override void action()        {            actionstring = "jump";        }    }}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.