Adapter mode (Adepter), which converts an interface of a class to another interface that the customer wants. The Adepter mode makes classes that cannot work together due to incompatibility of the mode, and can work together. In software development, when the data and behavior of the system are correct but the interface is inconsistent, we should consider using the adapter mode, the purpose is to match an existing object out of the control scope with an interface. The adapter mode is mainly used to reuse some existing classes, but the interfaces are inconsistent with the Reuse Environment, for example, it is of great practical value to reuse early-stage code and some functions. Adapter mode UML class diagram: Analysis: Target is the interface the customer expects, and the Target can be a specific or abstract class or interface; Adeptee is the class to be adapted; adepter is an adapter class. It encapsulates an Adeptee object internally to convert the source interface to the target interface. Adapter mode implementation: [csharp] using System; using System. collections. generic; using System. linq; using System. text; namespace Adepter {/** this is the interface the customer expects. The Target can be a specific or abstract class or an interface */class Target {public virtual void Request () {Console. writeLine ("common request... ") ;}}/*** class to be adapted */class Adeptee {public void SpecificRequest () {Console. writeLine ("special request... ") ;}}/** Adepter converts the source interface to the Target Interface by wrapping an Adeptee object internally */class Adepter: Target {private Adeptee adeptee = new Adeptee (); // this is a private Adeptee object public override void Request () {this. adeptee. specificRequest (); // you can call the Request () method on the surface and convert it to call the SpecificRequest () method // base. request () ;}} client: [csharp] using System; using System. collections. generic; using System. linq; using System. text; namespace Adepter {class Program {static void Main (string [] args) {Target target = new Ad Epter (); target. request (); // for the customer, the Request () Console of Target is called. read () ;}} adapter mode Summary: when using an existing class, but its interface is its method or your requirements are different; the two classes do the same thing or are similar, but the interfaces are different. You should consider using the adapter mode. In this way, the customer can call an interface in a unified manner, which is simpler, more direct, and more compact. Adapter mode case-Basketball translation adapter [csharp] using System; using System. collections. generic; using System. linq; using System. text; namespace AdepterExample {abstract class Player {private string name; public Player (string name) {this. name = name;} public string getName () {return this. name;} public void setName (string name) {this. name = name;} public abstract void Attack (); public abstract void Defense ();} cl Ass Forwards: Player {public Forwards (string name): base (name) {} public override void Attack () {Console. WriteLine ("forward {0}, Attack! ", This. getName (); // throw new NotImplementedException ();} public override void Defense () {Console. WriteLine (" forward {0}, defender! ", This. getName (); // throw new NotImplementedException () ;}} class Center: Player {public Center (string name): base (name) {} public override void Attack () {Console. writeLine ("center {0}, attack! ", This. getName (); // throw new NotImplementedException ();} public override void Defense () {Console. WriteLine (" center {0}, defender! ", This. getName (); // throw new NotImplementedException () ;}} class Guards: Player {public Guards (string name): base (name) {} public override void Attack () {Console. writeLine ("Defender {0}, attack! ", This. getName (); // throw new NotImplementedException ();} public override void Defense () {Console. WriteLine (" Defender {0}, defender! ", This. getName (); // throw new NotImplementedException () ;}} class ForeignCenter {private string name; public string getName () {return this. name;} public void setName (string name) {this. name = name;} public void attack () {Console. writeLine ("Foreign center {0}, attack! ", This. name);} public void () {Console. WriteLine (" Foreign center {0}, defender! ", This. name) ;}} class Adepter: Player {private ForeignCenter foreignCenter = new ForeignCenter (); public Adepter (string name): base (name) {foreignCenter. setName (name);} public override void Attack () {foreignCenter. attack (); // throw new NotImplementedException ();} public override void Defense () {foreignCenter. defense (); // throw new NotImplementedException () ;}} client: [csharp] using System; using System. collections. generic; using System. linq; using System. text; namespace AdepterExample {class Program {static void Main (string [] args) {Player p1 = new Forwards ("Battier"); Player p2 = new Adepter ("Yao Ming "); player p3 = new Guards ("mcgredy"); p1.Attack (); p2.Attack (); p3.Attack (); p2.Defense (); Console. read () ;}} running result: