I am writing a data driven WPF client. Typically, a client will retrieve data from a WCF service that queries SQL-db, but I would like it to retrieve data directly from SQL or other arbitrary data sources.
I came up with this design and would like to hear your opinion on whether it is the best design.
First we have some data object that we would like to extract from SQL.
public class Customer
{
private string m_Name = string.Empty;
public string Name
{
get { return m_Name; }
set { m_Name = value;}
}
}
Then I plan to use an interface that all levels of data access should implement. Suppose you can use an abstract class. Thoughts?
interface ICustomerFacade
{
List<Customer> GetAll();
}
You can create an SQL implementation.
public class SqlCustomrFacade : ICustomerFacade
{
public List<Customer> GetAll()
{
return new List<Customer>();
}
}
WCF. WCF , . , - . , , . ?
public class WcfCustomrFacade : ICustomerFacade
{
public List<Customer> GetAll()
{
List<WcfService.Customer> wcfCustomers = wcfService.GetAllCustomers();
List<Customer> customers = new List<Customer>();
foreach(WcfService.Customer wcfCustomer in wcfCustomers)
{
Customer customer = new Customer();
customer.Name = wcfCustomer.Name;
customers.Add(customer);
}
return customers;
}
}
factory, , .
public class FacadeFactory()
{
public static ICustomerFacade CreateCustomerFacade()
{
if (ConfigurationManager.AppSettings["DAL"] == "Sql")
return new SqlCustomrFacade();
else
return new WcfCustomrFacade();
}
}
DAL.
public class MyApp
{
public static void Main()
{
ICustomerFacade cf = FacadeFactory.CreateCustomerFacade();
cf.GetAll();
}
}
.