Big talk design mode-adapter Mode

Source: Internet
Author: User

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:


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.