Home  /  Questions  /  Question



50   50
Oct 18, 2012


Optimal Design Pattern to generate a file

The process to generate a file is : 1. get header 2. get content 4. generate file 6. download file
for exmple, there are two types: 1. txt file 2. xml file
the get header function is same. txt file and xml file use same function.
the get content function is different, different type file has different content. so I must use a interface and txt file and xml file to implete the interface.
the generate file function is same. use the header and the content to build a file.
the download file function is different, because system must give different file name base on type.
Does anyone have some examples,
Thanks



50   50
Nov 07, 2012
I suggest using Builder pattern to build different parts of the file. Depending on the different types, use Strategy pattern inside for each of them.