public static void Main()
QuickBooksCustomer qbCustomer = new QuickBooksCustomer() { Name = "John Smith" };
Customer ourAppEntity = ConvertEntity(qbCustomer) as Customer;
Console.Write(ourAppEntity.CustomerName);
public static ISyncService Create(Type qbEntityType)
Console.WriteLine("qbEntity type in Factory: " + qbEntityType.ToString());
if(qbEntityType == typeof(QuickBooksCustomer))
Console.WriteLine("qbEntity is QuickBooksCustomer, return CustomerSyncService.");
var service = new CustomerSyncService();
if(qbEntityType == typeof(QuickBooksVendor))
return new VendorSyncService();
throw new Exception("Invalid Type");
public class CustomerSyncService : ISyncService
public IEntity ConvertQBEntityToAppEntity(IQBEntity qbCustomer)
CustomerName = qbCustomer.Name
public class VendorSyncService : ISyncService
public IEntity ConvertQBEntityToAppEntity(IQBEntity qbVendor)
VendorName = qbVendor.Name
public static object ConvertEntity(IQBEntity qbEntity)
Console.WriteLine("qbEntity type to call Factory with: " + qbEntity.GetType().ToString());
var service = Create(qbEntityType: qbEntity.GetType());
if(service == null) Console.WriteLine("Service Factory returned null!!!");
var entity = service.ConvertQBEntityToAppEntity(qbEntity);
public interface IQBEntity {
string Name { get; set; }
public interface IEntity {
public interface ISyncService
IEntity ConvertQBEntityToAppEntity(IQBEntity qbEntity);
public class QuickBooksCustomer: IQBEntity{
public string Name { get; set; }
public class Customer: IEntity{
public int Id { get; set; }
public string CustomerName { get; set; }
public class QuickBooksVendor: IQBEntity{
public string Name { get; set; }
public class Vendor: IEntity{
public int Id { get; set; }
public string VendorName { get; set; }