The Builder Pattern separates the construction of a complex object from its representation so that several different representations can be created depending on the needs of the program.
“Separate the construction of a complex object from its representation so that the same construction process can create different representations.”
namespace BuilderPattern
{
public class Vehicle
{
public String GetVehicle(IVehicle iVehicle)
{
return iVehicle.GetModel();
}
}
}
namespace BuilderPattern
{
public interface IVehicle
{
String GetModel();
}
}
namespace BuilderPattern
{
public class Car :IVehicle
{
public string GetModel()
{
return "Car Model is Honda 2008";
}
}
}
namespace BuilderPattern
{
public class Bike : IVehicle
{
public string GetModel()
{
return "Bike Model is Yamaha 2007";
}
}
}
Create an aspx page ,add the below in the page load
void Page_Load(object sender, EventArgs e)
{
BuilderPattern.Vehicle vehicle = new BuilderPattern.Vehicle();
BuilderPattern.IVehicle iVehicle = new BuilderPattern.Car();
Response.Write(vehicle.GetVehicle(iVehicle));
}