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.
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
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.
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.
No comments:
Post a Comment