Everyone knows what power adapters do: Convert the voltage needed by each electric appliance. Similarly, this adapter works similarly.
When to use it, mainly for post-project maintenance. It is best not to use the adapter mode during design.
Figure:
The following uses Yao Ming's attempt to play basketball in the NBA as an example:
Code: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PC9wPgo8cHJlIGNsYXNzPQ = "brush: java;"> class Program {static void Main (string [] args) {Player B = new Forwards ("Battier"); B. attack (); Player m = new Guards ("Mike Grace"); m. attack (); Player ym = new Translator ("Yao Ming"); ym. attack (); ym. defense (); Console. read () ;}// abstract base class abstract class Player {protected string name; public Player (string name) {this. name = name;} public abstract void Attack (); public abstract void Defense ();} // forward class Forwards: Player {public Forwards (string name): base (name) {} public override void Attack () {// throw new NotImplementedException (); Console. writeLine ("forward {0} attack", name);} public override void Defense () {// throw new NotImplementedException (); Console. writeLine ("Striker {0} Defender", name) ;}// Center class Center: Player {public Center (string name): base (name) {} public override void Attack () {// throw new NotImplementedException (); Console. writeLine ("center {0} attack", name);} public override void Defense () {// throw new NotImplementedException (); Console. writeLine ("center {0} defense", name) ;}// guard class Guards: Player {public Guards (string name): base (name) {} public override void Attack () {// throw new NotImplementedException (); Console. writeLine ("Defender {0} attack", name);} public override void Defense () {// throw new NotImplementedException (); Console. writeLine ("Defender {0} Defender", name) ;}// foreign center class ForeignCenter {private string name; public string Name {get {return name ;} set {name = value ;}} public void Attack () {Console. writeLine ("Foreign center {0} attack", name);} public void Defense () {Console. writeLine ("Foreign center {0} Defender", name) ;}// translation class Translator: Player {private ForeignCenter wjzf = new ForeignCenter (); public Translator (string name ): base (name) {wjzf. name = name;} public override void Attack () {// throw new NotImplementedException (); wjzf. attack ();} public override void Defense () {// throw new NotImplementedException (); wjzf. defense ();}}
Running result: