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 #