Thebuilder pattern is adesign pattern that provides a flexible solution to various object creation problems inobject-oriented programming. The builder patternseparates the construction of a complex object from its representation. It is one of the 23 classic design patterns described in the bookDesign Patterns and is sub-categorized as acreational pattern.[1]
The builder design pattern solves problems like:[2]
Creating and assembling the parts of a complex object directly within a class is inflexible. It commits the class to creating a particular representation of the complex object and makes it impossible to change the representation later independently from (without having to change) the class.
The builder design pattern describes how to solve such problems:
Builder object.Builder object instead of creating the objects directly.A class (the same construction process) can delegate to differentBuilder objects to create different representations of a complex object.
The intent of the builder design pattern is to separate the construction of a complex object from its representation. By doing so, the same construction process can create different representations.[1]
Advantages of the builder pattern include:[3]
Disadvantages of the builder pattern include:

In the aboveUMLclass diagram,theDirector class doesn't create and assemble theProductA1 andProductB1 objects directly.Instead, theDirector refers to theBuilder interface for building (creating and assembling) the parts of a complex object,which makes theDirector independent of which concrete classes are instantiated (which representation is created).TheBuilder1 class implements theBuilder interface by creating and assembling theProductA1 andProductB1 objects.
TheUMLsequence diagram shows the run-time interactions:TheDirector object callsbuildPartA() on theBuilder1 object, which creates and assembles theProductA1 object.Thereafter,theDirector callsbuildPartB() onBuilder1, which creates and assembles theProductB1 object.

AC# example:
namespaceWikipedia.Examples;/// <summary>/// Represents a product created by the builder./// </summary>publicclassBicycle{publicBicycle(stringmake,stringmodel,stringcolour,intheight){Make=make;Model=model;Colour=colour;Height=height;}publicstringMake{get;set;}publicstringModel{get;set;}publicintHeight{get;set;}publicstringColour{get;set;}}/// <summary>/// The builder abstraction./// </summary>publicinterfaceIBicycleBuilder{BicycleGetResult();stringColour{get;set;}intHeight{get;set;}}/// <summary>/// Concrete builder implementation./// </summary>publicclassGTBuilder:IBicycleBuilder{publicBicycleGetResult(){returnHeight==29?newBicycle("GT","Avalanche",Colour,Height):null;}publicstringColour{get;set;}publicintHeight{get;set;}}/// <summary>/// The director./// </summary>publicclassMountainBikeBuildDirector{privateIBicycleBuilder_builder;publicMountainBikeBuildDirector(IBicycleBuilderbuilder){_builder=builder;}publicvoidConstruct(){_builder.Colour="Red";_builder.Height=29;}publicBicycleGetResult(){returnthis._builder.GetResult();}}publicclassClient{publicvoidDoSomethingWithBicycles(){MountainBikeBuildDirectordirector=new(newGTBuilder());// Director controls the stepwise creation of product and returns the result.director.Construct();BicyclemyMountainBike=director.GetResult();}}
The Director assembles a bicycle instance in the example above, delegating the construction to a separate builder object that has been given to the Director by the Client.