Builder Pattern Code Review

Define the Factory Director and Factory Product Objects

Code Review

Code Walkthrough

The FactoryDirector class (object) represents a Director class.

class FactoryDirector { public void Construct(IProductBuilder builder) { builder.BuildFrame(); builder.BuildEngine(); builder.BuildWheels(); builder.BuildDoors(); } }

This class invokes the methods associated with a specific Builder class to construct a particular object.

The FactoryProduct class (object) defines the details stored about a particular product.

class FactoryProduct { private StringDictionary parts = new StringDictionary(); private String productType = String.Empty;
public FactoryProduct(String type) { this.productType = type; }
public String this[String key] { get { return this.parts[key]; } set { this.parts[key] = value; } }
public void DisplayProduct() { Console.WriteLine("\n"); Console.WriteLine("Product Type: {0}", this.productType); Console.WriteLine("\tFrame: {0}", this.parts["frame"]); Console.WriteLine("\tEngine: {0}", this.parts["engine"]); Console.WriteLine("\tWheels: {0}", this.parts["wheels"]); Console.WriteLine("\tDoors: {0}", this.parts["doors"]); } }