Bridging mode (bridge fabric mode) C #

Source: Internet
Author: User

Bridge mode (bridge structure mode) C # simple Example

Each additional action in the previous player must be added to each player, and the behavior is extracted by bridging mode to reduce the change

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 (Intent) separates the abstract part from the implementation part so that they can all be changed independently.        Public abstract class play//abstract section {public string playstring {get; set;}        Protected Playaction PA;        public void Setplayaction (playaction pa)//use combination {THIS.PA = PA; public abstract void Action ();//AbstractPartial change public void run () {pa.action ();//Implement partial action (); }} public class Play1:play {public override void action () {playstring = "play1" + P        a.actionstring; }} public class Play2:play {public override void action () {playstring = "play2" + P        a.actionstring;        }} public abstract class playaction//the implementation part of the abstract {public string actionstring;    public abstract void action ();  } public class move:playaction//implements player move behavior {public override void action () {actionstring =        "Move"; }} public class jump:playaction//implements player jumping behavior {public override void action () {ACTIONSTR        ing = "jump"; }    }}


Bridging mode (bridge fabric mode) C #

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.