Builder Pattern

-> Builder pattern is useful when you need to create an object with lots of possible configuration options.
-> Builder is a creational design pattern that lets you produce different types and representations of an object using the same building process. Builder allows constructing complex objects step by step.
-> The builder pattern can be recognized in class, which has a single creational method and several methods to configure the resulting object. Builder methods often support chaining (sombuilder -> setValueA(1) -> setValueB(2) -> create()).

Builder
-> Declares steps required to build a product.
Concrete Builders
-> provide different implementations of the construction steps. Builders can also provide methods for fetching a construction result. This method can not be declared inside the builder interface, because builders may produce products that do not have the common interface. But if you are dealing with products from a single hierarchy, then this method can be safely described in the base interface.
Product
-> Product is an object created as a result of construction. Builders can produce products that do not belong to the same class hierarchy or interface. It is a key difference between the Builder and other creational patterns.
Director
-> constructs products using a Builder object. Usually, client assigns a builder instance to a director just once via constructor parameters. Then director uses that single builder object for all further construction. But there is an alternative when a builder is passed to the main production method of a director.

Leave a Reply

Your email address will not be published. Required fields are marked *