What is the need for Builder Pattern in C#?Builder pattern
is used to separate representation from construction of objects. Rather
than deciding what are the entities used in your application, builder
pattern helps you in designing how to present those entities. Assume that
you are dealing with the entity Car in your application.
You will include Car as a class and inherit it into different derived classes namely Toyota, Tata Indica and many more. All this is about the representation of entity Car. But there is also a necessity to focus on how Car can be constructed? What are its assembly parts? And so on. Such construction details will be maintained in an abstract builder class which can then be inherited and overridden based on the type of Car. Here is a sample builder class for Car construction: abstract
class CarBuilder { This builder class contains abstract methods to define construction of parts of a car. If you look at the overall architecture of your application, CarClass and its inherited classes will give you the representation of Car. CarBuilder and its inherited classes will maintain details about the construction of Car and its inherited types. Representation and Construction are related by creating an instance of CarClass as a member of CarBuilder.
|