Builder pattern falls under the Creational design pattern. The Builder pattern separates the construction phase of a complex object from its representation so that the same construction logic can be used for different objects and the output representation may be different. Using the same construction logic, we will get different object representations.
I have used the scenario for creation of reports as the example. We can create either PDF or Excel reports.
ReportBuilder class has the construction logic for building the individual parts of the Report. Director takes ReportBuilder as argument and then defines the sequence for building the report. The end result is the Report which can either be Excel or PDF.
The code snippet for this pattern is as seen below :