2016-09-21 21 views

答えて

0

あなたの場合、私はBuilderパターンを提案します。 Javaで実装するのは簡単です。オブジェクトの作成プロセスをカプセル化するのに役立ちます。 PDFExportDataのコンストラクタをprivate(便宜上)と宣言し、静的なクラスをに追加してください。ここ

は一例であり:

public class PDFExportData extends ProjectExportData { 

    final String myStylesheet; 

    public static class PDFExportDataBuilder { 

     private GanttExportSettings myExportSettings; 
     private File myOutputFile; 
     private String myProjectName; 
     private String myProjectDescription; 
     private String myOrganization; 
     private HumanResourceManager myResourceManager; 
     private TaskContainmentHierarchyFacade myTaskHierarchyFacade; 
     private GanttChartExportProcessor myGanttChartExportProcessor; 
     private ResourceChartExportProcessor myResourceChartExportProcessor; 
     private String stylesheet; 

     public PDFExportDataBuilder setMyExportSettings(GanttExportSettings myExportSettings) { 
      this.myExportSettings = myExportSettings; 
      return this; 
     } 

     public PDFExportDataBuilder setMyOutputFile(File myOutputFile) { 
      this.myOutputFile = myOutputFile; 
      return this; 
     } 

     public PDFExportDataBuilder setMyProjectName(String myProjectName) { 
      this.myProjectName = myProjectName; 
      return this; 
     } 

     public PDFExportDataBuilder setMyProjectDescription(String myProjectDescription) { 
      this.myProjectDescription = myProjectDescription; 
      return this; 
     } 

     public PDFExportDataBuilder setMyOrganization(String myOrganization) { 
      this.myOrganization = myOrganization; 
      return this; 
     } 

     public PDFExportDataBuilder setMyResourceManager(HumanResourceManager myResourceManager) { 
      this.myResourceManager = myResourceManager; 
      return this; 
     } 

     public PDFExportDataBuilder setMyTaskHierarchyFacade(TaskContainmentHierarchyFacade myTaskHierarchyFacade) { 
      this.myTaskHierarchyFacade = myTaskHierarchyFacade; 
      return this; 
     } 

     public PDFExportDataBuilder setMyGanttChartExportProcessor(GanttChartExportProcessor myGanttChartExportProcessor) { 
      this.myGanttChartExportProcessor = myGanttChartExportProcessor; 
      return this; 
     } 

     public PDFExportDataBuilder setMyResourceChartExportProcessor(ResourceChartExportProcessor myResourceChartExportProcessor) { 
      this.myResourceChartExportProcessor = myResourceChartExportProcessor; 
      return this; 
    } 

     public PDFExportDataBuilder setStylesheet(String stylesheet) { 
      this.stylesheet = stylesheet; 
      return this; 
     } 

     public PDFExportData create() { 
      return new PDFExportData(this); 
     } 
    } 

    private PDFExportData(PDFExportData.PDFExportDataBuilder b) { 
     super(b.myExportSettings, b.myOutputFile, b.myProjectName, b.myProjectDescription, b.myOrganization, b.myResourceManager, b.myTaskHierarchyFacade, b.myGanttChartExportProcessor, b.myResourceChartExportProcessor); 

     myStylesheet = b.stylesheet; 
    } 
} 

そして、この後にインスタンスはそう臭い容易ではなく、静かである。

公共の静的な無効メイン(文字列[]引数)例外{

をスロー
PDFExportData pdf = new PDFExportData.PDFExportDataBuilder() 
      .setMyExportSettings(new GanttExportSettings()) 
      .setMyGanttChartExportProcessor(new GanttChartExportProcessor()) 
      .setMyGanttChartExportProcessor(new GanttChartExportProcessor()) 
      /// .... 
      .create(); 
} 

この場合、必要なすべてのパラメータをビルダーに渡す必要があります。

Bundleを作成して、PDFExportDataコンストラクタに渡す必要があるすべての値を格納することもできます。

関連する問題