Sunday, 23 December 2012

What is Bridge pattern in dotnet



Yes, Bridge pattern comes under structural pattern. We know structural patterns means making relationship between the objects(entities).  Which makes easier for different components of an application to interact with each other.

Bridge Pattern:
Yes, Bridge pattern comes under structural pattern. We know structural patterns means making relationship between the objects(entities).  Which makes easier for different components of an application to interact with each other.
Separates an objects interface from its implementation.
interface IConnections
    {
        void Open();
        void Close();

    }-à IDbConnection
Then 

    abstract class DatabaseConnection:IConnections
    {

        public  abstract void Open();
        public abstract void Close();
    }-à DbConnection


Then        //SqlConnection  // system.data.sqlclient

class SqlserverConnection:DatabaseConnection  
    {  
      
        public override void Open()
        {
            Console.Write("sqlserconnection is opened");
        }

        public override void Close()
        {
            Console.Write("sqlserconnection is closed");
        }
    }

As well    // OracleConnection  // system.data.oracleclient

    class OracleserverConnection:DatabaseConnection
    { 
           

        public override void Open()
        {
            Console.Write("oracleconnection is opened");
        }

        public override void Close()
        {
            Console.Write("oracleconnection is opened");
        }
    }
Now as per the creation of serverconnection(sql server,oracle ..ect) their relavent connection will be opened.
class Program
    {
        static void Main(string[] args)
        {
          // SqlConnection
           // SqlserverConnection conss = new SqlserverConnection();
            OracleserverConnection conss = new OracleserverConnection();
            conss.Open();
            Console.ReadKey();
        }
    }

No comments:

Post a Comment