1. Features: The interface incompatible classes can work together. Mend
2. Concept: Adapter mode, which transforms the interface of one class into another interface that the customer wants. The adapter mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work together.
3. Class Diagram:
4. Program implementation:
<summary>///Define client-expected interface///</summary> public class Target {///<summary> Use virtual adornments so that subclasses can rewrite//</summary> public virtual void Request () {Console.wri Teline ("This is a common request"); }}///<summary>///define the classes that need to be adapted////</summary> public class Adaptee {public void Spec Ificrequest () {Console.WriteLine ("This is a special request."); }}///<summary>//define Adapter///</summary> public class Adapter:target {//Establish a private ad Eptee Object Private Adaptee adaptee = new Adaptee (); <summary>/////By rewriting the request () method on the surface, it becomes the actual call to Specificrequest ()///</summary> public ov erride void Request () {adaptee. Specificrequest (); }}class program {static void Main (string[] args) {//For the client, call is the request of target () Target target = new Adapter (); Target. Request (); Console.read (); } }
Design Pattern Learning Notes-Adapter mode