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

Bridge pattern compose objects in tree structure. It decouples abstraction from implementation. Here abstraction represents the client where from the objects will be called.



# region The Implementation
    /// <summary>
 post">

Bridge Pattern

Bridge pattern compose objects in tree structure. It decouples abstraction from implementation. Here abstraction represents the client where from the objects will be called.

/// Helps in providing truely decoupled architecture
    /// </summary>
    public interface IBridge
    {
        void Function1();
        void Function2();
    }
 
    public class Bridge1 : IBridge
    {
 
        #region IBridge Members
 
        public void Function1()
        {
            throw new NotImplementedException();
        }
 
        public void Function2()
        {
            throw new NotImplementedException();
        }
 
        #endregion
    }
 
    public class Bridge2 : IBridge
    {
        #region IBridge Members
 
        public void Function1()
        {
            throw new NotImplementedException();
        }
 
        public Function1()
        {
            void Function2()
        {
            throw new NotImplementedException();
        }
 
        #endregion
    }
    # endregion
 
    # region Abstraction
    public interface IAbstractBridge
    {
        void CallMethod1();
        void CallMethod2();
    }
 
    public class AbstractBridge : IAbstractBridge
    {
        public IBridge bridge;
 
        public AbstractBridge(IBridge bridge)
        {
            this.bridge = bridge;
        }
        #region IAbstractBridge Members
 
        public void CallMethod1()
        {
            this.bridge.Function1();
        }
 
        public void CallMethod2()
        {
            this.bridge.Function2();
        }
 
        #endregion
    }
    # endregion

Thus you can see the Bridge classes are the Implementation, which uses the same interface oriented architecture to create objects. On the other hand the abstraction takes an object of the implementation phase and runs its method. Thus makes it completely decoupled with one another.