I have been studying design pattern of "Gang of four design pattern".
I need to design data layer to handle multiple database as well as extend the function if required. The database could one is SQL, one XMl or some external system database.
What would be good design pattern to follow?
Edit:
Based on suggestion, i tried to implement DAO and Factory pattern in Data layer. To an extent i could get to the point.
But As per GOF desgin pattern, The data provider name decided which database object i can call.
Like below. Where as i am trying to make the layer dynamic so that multiple database can handled. If i follow below pattern then i can only access one database in one application.
If somebody has looked into Gang of Four Design pattern then Please guide me.
public class DaoFactories
{
public static IDaoFactory GetFactory(string dataProvider)
{
// Return the requested DaoFactory
switch (dataProvider)
{
case "ADO.NET.Access": return new AdoNet.Access.AccessDaoFactory();
case "ADO.NET.Oracle": return new AdoNet.Oracle.OracleDaoFactory();
case "ADO.NET.SqlExpress":
case "ADO.NET.SqlServer": return new AdoNet.SqlServer.SqlServerDaoFactory();
case "LinqToSql.SqlExpress":
case "LinqToSql.SqlServer": return new LinqToSql.Implementation.LinqDaoFactory();
case "EntityFramework.SqlExpress":
case "EntityFramework.SqlServer": return new EntityFramework.Implementation.EntityDaoFactory();
// Default: SqlExpress
default: return new AdoNet.SqlServer.SqlServerDaoFactory();
}
}
}
Best Answer
You should look into the Repository Pattern and Data Access Object Pattern