私のアプリケーションにFactory pattern
を実装しようとしています。Cで工場設計パターンを実装する方法
これらのリンクを参照して、私は実装しようとしていますが、1つの場所に貼り付けています&続行方法がわかりません。
- How to update this class/method to improve Code Metrics
- http://www.dofactory.com/net/factory-method-design-pattern
- How to implement Factory pattern?
私は立ち往生午前どこ得るために、私 コード内のコメントを "どのように私はここに実装するのですここで混乱し//" を見つけてください。
//DAL Layer
public interface IReportHandler
{
IEnumerable<DocumentMapper> FetchDocumentsList(Guid clientId, int pager = 0);
}
public class ReportHandler : IReportHandler
{
public IEnumerable<DocumentMapper> FetchDocumentsList(Guid clientId, int pager = 0)
{
//implentation of the method
}
}
//BLL
public interface IReportFactory
{
IReportHandler Create(int factoryId);
}
public class ReportFactory : IReportFactory
{
private IReportHandler reportObj;
public override IReportHandler Create(int factoryId)
{
switch (factoryId)
{
case 1:
reportObj = new ReportHandler();
return reportObj;
default:
throw new ArgumentException("");
}
}
}
//UI Layer
public String GetAllDocuments(string url,int pager =0)
{
if (SessionInfo.IsAdmin)
{
string documents ;
//call GetDocumentIntoJson() private method
}
else
{
return "Sorry!! You are not authorized to perform this action";
}
}
private static string GetDocumentIntoJson(int clientId, int pager)
{
// confused here how do I implement here
IReportHandler dal = ReportFactory
var documents = dal.FetchDocumentsList(clientId, pager);
string documentsDataJSON = JsonConvert.SerializeObject(documents);
return documentsDataJSON;
}
誰かが工場出荷時のパターンを実装+私のコード・スニペットを改善するために私を導くことはできますか?
非常に高く評価されているヘルプ/提案。
あなたの元の意図は何ですか?あなたは工場が必要と思いますか? – guillaume31
コードレビューで同一人物からも尋ねられているので、この質問を議論の対象外としています。http://codereview.stackexchange.com/questions/150382/工場向けレポートハンドラー –