Builder Pattern can help create a series of objects which creation process is complicated and the step under creation process is similar but just needs to specific the details.
There are several roles in builder pattern, director, builders, abstract builder and the product.
Abstract builder will provide the template of the steps under product creation process, different product builder will extend abstract builder and implement each step details.
Director doesn't need to know each step details of creation process, but combine the steps to completed creation process accordingly.
Director class:
public class Director {
public House buildHouse(Builder builder) {
builder.buildFoundation();
builder.buildWall();
builder.buildRoof();
return builder.startBuild();
}
}
Test class, create object:
public static void main(String[] args) {
Director director = new Director();
House mall = director.buildHouse(new MallBuilder());
House normalHouse = director.buildHouse(new NormalHouseBuilder());
}