Results 1 to 1 of 1
Thread: Builder pattern
- 01-21-2011, 10:15 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
Builder pattern
Hello,
I am new to design patterns, but willing to learn. So I came here for an advice, as this would be my first attempt in implementing the builder pattern.
The project: Create a java application that will generate and send via email 6 exports (Excel files) of different types, having their data filled from a database. The names of the exports, as well as other filters, will be read from an XML file passed as an argument in the command line.
My solution was to use the builder pattern, as it follows:
Buider:
Java Code:public abstract class BuilderExport { protected Expor export; public Export getExport(){ return export; } public void createExport(){ export = new Export(); } public abstract void createAntet(); public abstract void createTableHead(); public abstract void createTable(); public abstract void setPath(); }
ConcreteBuilder:
Director:Java Code:public class BuilderExportImplementationA extends BuilderExport { private ExportFilters filters; public BuilderExportImplementationA(ExportFilters ef){ this.filters = ef; } //..overrided methods }
Java Code:public class DirectorExport { private BuilderExport builder; public DirectorExport (BuilderExport b){ this.builder= b; } public Export getExport(){ return builder.getExport(); } public void createExport(){ builder.createExport(); builder.createAntet(); builder.createTableHead(); builder.createTable(); builder.setPath(); } }
Product:
Java Code:public class Export { private Workbook workbook; private Sheet sheet; private String path; public Export(){ workbook = new HSSFWorkbook(); } //...getters and setters }
Application:
Java Code:.... public static void main(String[] args) { BuilderExport builder = null; List<ExportFilters> listFilters; DirectorExport director; ... for (ExportFilters fe : listFilters) { if (fe.getType().equals("A")) { builder = new BuilderExportImplementationA (fe); } else if (fe.getType().equals("B")) { ... director= new DirectorExport (builder ); director.createExport(); } }
Can someone please tell me if this design is well thought? Is there another design pattern better suited for this problem ?
Another question: the methods saveExport(String path) and sendExport(..) to which object will they belong?
I would appreciate any help you can give me.
Thanks.
ps: Please excuse my grammar, as english is not my native language.Last edited by 31vl; 01-21-2011 at 10:19 AM.
Similar Threads
-
strategy pattern and bridge pattern
By jomypgeorge in forum New To JavaReplies: 2Last Post: 12-13-2010, 05:13 AM -
Best GUI Builder
By ergon78 in forum SWT / JFaceReplies: 1Last Post: 09-14-2010, 01:02 PM -
Class pattern to generate following pattern:-
By vxs in forum New To JavaReplies: 5Last Post: 07-14-2010, 11:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks