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 {
protected CarClass carObj;
public Car CarObj {
get { return carObj;}
}
public abstract void buildCarEngine();
public abstract void buildCarWheels();
public abstract void buildCarDoors();
public abstract void buildCarWindows();
}

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.

| What is the need for Bridge Pattern in C#? | What is the need for Builder Pattern in C#? | What is the need for Chain of Responsibility Pattern in C#? | What is the need for Command Pattern in C#? | What is the need for Composite Pattern in C#? | What is the need for Decorator Pattern in C#? | What is the need for Flyweight Pattern in C#? | What is the need for Interpreter Pattern in C#? | What is the need for Iterator Pattern in C#? | What is the need for Mediator Pattern in C#? | What is the need for Memento Pattern in C#? | What is the need for Prototype Pattern in C#? | What is the need for State Pattern in C#? | What is the need for Strategy Pattern in C#? | What is the need for Template Method Pattern in C#? | What is the need for unsafe code in C#? | What is the purpose of assert() in C#? | What is the purpose of AutoResetEvent in .NET? | What is the purpose of Console.ReadLine() in C#? | What is the purpose of machine.config file in .NET? |


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.