Search code examples
c#.netdesign-patternsfactory-pattern

Should I use a factory here


I have a simple class ExcelStringBuilder. Its used to build a string that can be exported to Excel. Now I need to build a CSV string also.

The only difference that I see for implementing both of these classes is the delimiter that is to be used while building the string. For Excel it would be "\t" tab character and CSV its "," comma.

What I think is to pass the delimiter as a parameter to the ExcelStringBuilder class constructor. Will that be a right decision or should I go for factory pattern?


Solution

  • Don't overdesign it. I would just refactor the existing class slightly:

    • rename it to something like ExportStringBuilder
    • pass the delimiter in the constructor, or as an argument of the ToString() function

    You are aware that there are some great free libraries available for this, are you? E.g. see this question