Showing posts with label Design Patterns. Show all posts
Showing posts with label Design Patterns. Show all posts

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();
        }
    }

Friday, 2 November 2012

What is Adapter Pattern and how it is implementated in .net?

Adapter Pattern:
This pattern is comes under àstructural pattern
Structural Pattern makes à grouping objects(related objects)together with good standarazation.
Example:
SqlDataAdapter Fill() -à Method. Which has their own implementation(with one more interfaceà interface IDataAdapter).
Yes,
public interface IDataAdapter
{
int Fill(DataSet dataSet);  // by default : virtual, public

}
Based on the type of DataAdapteràSqlDataAdapter,OracleDataAdapter…are implements DbDataAdapter.
Base on the type of DataAdapter(SqlDataAdapter,OracleDatapter..)

DbDataAdapter provides the underlaing implementation as per the DataAdapter.
Here
public interface IDataAdapter
{
int Fill(DataSet dataSet);  // by default : virtual, public ,abstract *****
}

Which

Class DbDataAdapter : DataAdapter
{
public override int Fill(DataSet dataSet);
}

SqlDataAdapter : DbDataAdapter
OracleDataAdapter : DbDataAdapter
As well we have SqlDataAdapter,OracleDataAdapter…ect these all are derived from DbDataAdapter class.
Which(DbDataAdapter) makes the Fill() method to their apporiate Sql/Oracle/oldedb—Adapter implementation. 


Note: as per the type of Adapter -->the relavent object is not created(like creation pattern). instead of creation the relavent implementation is called by DbDataAdapter abstract class(structural pattern).

So
SqlConnection con = new SqlConnection("uid=sa;pwd=zolt123$;database=wcfdb");

SqlDataAdapter da = new SqlDataAdapter("select * from emp", con);
DataSet ds = new DataSet();da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];

da.Fill(ds)………………>(DbDataAdapter).Fill()   // here da is SqlDataAdapter.

as well
OleDbConnection con = new OleDbConnection("uid=sa;pwd=zolt123$;database=wcfdb");
OleDbDataAdapter da = new OleDbDataAdapter("select * from emp", con);
DataSet ds = new DataSet();da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
da.Fill(ds)………………>(DbDataAdapter).Fill()  // here da is OracleDataAdapter.

----Adapter pattern makes objects grouping together. with same programming style.
Fill()
Fill()method implementation is different from Adapter to Adapter(sql/oracle/oledb).so making good standarazation microsoft defines IDataAdatper interface and DataAdapter classes.

DataAdapter :IDataAdapter
and
DbDataAdapter: DataAdapter
and
SqlDataAdapter : DbDataAdapter

SqlDataAdapter implementation inside-à DbDataAdapter(not in SqldataAdapter).
OracleDataAdapter implementation inside-àDbDataAdapter(not in OracledataAdapter).

we can say this implementation as -->Abstraction. why because based on the type of dataadapter to working with their apporiate mdf, ldf files to fill dataset.

Open() and Close() relavent-to methods---SqlConnection has their own implementation.----IDbConnection not like Fill() method.

Monday, 22 October 2012

What is Design Pattern and Types of Design patterns?


Design Patterns are coding level constraints to build an efficent and Proveded soluations for recurring problems while building Software systems/applications using Object Oriented Programming.

Design Patterns independent language soluations.

Design Patterns are ready-made soluations for object oriented programming.

Types of design patterns:

yes, GOF(Gang of Four) Categoriges into 3 types based on their main objective.

1. Creational Patterns(creation of objects):
                                     Creating objects an Efficient way.
 these types of patterns are used to define an efficient way of creating objects[un-unnecessarily using new keyword].
these types of patterns uses base types to create objects. [un-aware of concreate classes to define].

these types patterns uses creation of objects. which provide more generic implementation[by hiding concreate classes throug using Factory interfaces/Factory Classes].

Creational Patterns:

Single Pattern  : creates single instance and shares the same object[single object]to multiple clients.

Factory Method Pattern :create object based on the type of input which[generic implementation] generates their apporiate derived objects.

these uses factory types to create object(single object) which create further derived object of same input type object.
 which generally done through methods like

--cmd.CreateConnection()
--cmd.CreateCommand();
                                          .....ect

Abstract Factory Pattern:  creates collection of objects for the Factory types.this exactly Abstract Factory Pattern--->create objects of Factory Types.

DbProviderFactory:--->which are base types for other factory types
         SqlclientFactory.
        OracleClientFactory,....ect. which creates an apporiate derived types.

Builder Pattern: when we require object construction from its representation. when object construction is complex from it's representation(final output:end result).

commandBuilder,StringBuilder,...ect

Structural Patterns:
                              Abstraction and Implementation and abstraction through their own classes.
advantage : through avoiding copuling( achiving decopuling)

makes object relationships(objects get together) to build large system. without distrub existing implementation.[using addtional interfaces and abstract classes]. these objects from different components.

Interfaces----good  Standarzation of coding.
Classes-------good for providing implementation/avoiding copuling(or)decopuling.

Adapter Pattern : makes implementation is sperateded to their own classes.

SqlDataAdapter, OracleDataAdapter.....ect

Bridge Pattern   : makes implementation in thier own classes/concreate classes and Providing abstraction.

--open() and --close() methods of SqlConnection.
--open(0 and --close() methods of OracleConnection.

Proxy pattern...ect

Behavioural Patterns:

           communication and dispatching of responsibilities  between objects. By doing so, these patterns increase flexibilities in carrying out this communication improves. They shift your focus from flow of control to the way objects are interconnected.
                                   these patterns improve the communication between different objects in a flexibility.

Chain and Responability
Observe pattern
State pattern
Stagery pattern....ect


References:

http://dotnetascent.blogspot.in/search/label/Design%20Patterns, dotnetuncle,..ect