Adapter Pattern - TechNet Articles - United States (English) - TechNet Wiki

Adapter pattern converts one instance of a class into another interface which client expects. In other words, Adapter pattern actually makes two classes compatible.



public interface IAdapter
    

Adapter Pattern

Adapter pattern converts one instance of a class into another interface which client expects. In other words, Adapter pattern actually makes two classes compatible.



{
        /// <summary>
        /// Interface method Add which decouples the actual concrete objects
        /// </summary>
        void Add();
    }
    public class MyClass1 : IAdapter
    {
        public void Add()
        {
        }
    }
    public class MyClass2
    {
        public void Push()
        {
 
        }
    }
    /// <summary>
    /// Implements MyClass2 again to ensure they are in same format.
    /// </summary>
    public class Adapter : IAdapter
    {
        private MyClass2 _class2 = new MyClass2();
 
        public void Add()
        {
            this._class2.Push();
        }
    }

Here in the structure, the adapter is used to make MyClass2 incompatible with IAdapter.