I am in process of building an application that converts documents from and to different formats. For example it will covert Word, Excel to PDF. To do so I use Office API and multiple third party libraries.
For example, if Excel is installed on user's computer I will be using Excels' API otherwise will use a third party library to do the job. My problem is in implementing Abstract Factory Pattern. I added class library for each component: "MsExcel", "Excel3rdParty", "MsWord", "Word3rdParty", "PDF" and "Common". Each project references "Common" project where I plan to keep all Interfaces and each class library will implement its own component. I apologize in advance for noob question but home someone can help me because already 2nd week i am trying to make it work and no luck. Thank in advance!
public interface IOfficeFactory
{
IExcelFactory GetExcelDocument(string documentType);
}
public class ExcelFactory : IOfficeFactory
{
public IExcelFactory GetExcelDocument(string documentType)
{
switch(documentType)
{
case "Excel":
return new Excel();
case "IExcel3rdParty":
return new IExcel3rdParty();
default:
throw new ApplicationException(documentType + "type can not be created");
}
}
}
public class IExcel3rdParty : IExcelFactory
{
public IExcelFactory GetExcelDocument(string documentType)
{
return new IExcel3rdParty();
}
}
public class Excel : IExcelFactory
{
public IExcelFactory GetExcelDocument(string documentType)
{
return new Excel();
}
}
public interface IExcelFactory
{
}
public interface IExcel : IExcelFactory
{
}
public interface IIExcel3rdParty : IExcelFactory
{
}
Aucun commentaire:
Enregistrer un commentaire