public static void Main()
Console.WriteLine("Hello World");
PhoneEngineer engineer = new PhoneEngineer();
IPhoneBuilder phoneBuilder= null;
phoneBuilder = new AndroidBuilder();
engineer.Construct(phoneBuilder);
Console.WriteLine("A new phone built: \n\n{0}", phoneBuilder.Phone.ToString());
phoneBuilder = new WindowsPhone();
engineer.Construct(phoneBuilder);
Console.WriteLine("A new phone built: \n\n{0}", phoneBuilder.Phone.ToString());
public enum ScreenType {Touch_Capacitive, Touch_Resistive, Non_Touch}
public enum Battery {MAH_1000, MAH_1500, MAH_2000}
public enum OperatingSystem {Android, Windows_Mobile, Window_Phone, Symbian}
public enum Stylus {Yes, No}
public string PhoneName {get;set;}
public MobilePhone(string name)
public ScreenType PhoneScreen {get; set;}
public Battery PhoneBattery {get; set;}
public OperatingSystem PhoneOS {get; set;}
public Stylus PhoneStylus {get; set;}
public override string ToString()
return string.Format("Name: {0}\nScreen: {1}\nBattery: {2}\nOS: {3}\nStylus: {4}",PhoneName, PhoneScreen, PhoneBattery, PhoneOS, PhoneStylus);
public interface IPhoneBuilder
public class AndroidBuilder : IPhoneBuilder
phone = new MobilePhone("Andorid");
public void BuildScreen(){phone.PhoneScreen = ScreenType.Touch_Capacitive;}
public void BuildBattery(){phone.PhoneBattery = Battery.MAH_1500;}
public void BuildOS(){phone.PhoneOS = OperatingSystem.Android;}
public void BuildStylus() {phone.PhoneStylus = Stylus.Yes;}
public MobilePhone Phone { get {return phone;}}
public class WindowsPhone: IPhoneBuilder
phone = new MobilePhone("Windows");
public void BuildScreen(){phone.PhoneScreen = ScreenType.Touch_Resistive;}
public void BuildBattery(){phone.PhoneBattery = Battery.MAH_2000;}
public void BuildOS(){phone.PhoneOS = OperatingSystem.Window_Phone;}
public void BuildStylus() {phone.PhoneStylus = Stylus.Yes;}
public MobilePhone Phone { get {return phone;}}
public class iPhonePhone: IPhoneBuilder
phone = new MobilePhone("iPhone");
public void BuildScreen(){phone.PhoneScreen = ScreenType.Non_Touch;}
public void BuildBattery(){phone.PhoneBattery = Battery.MAH_1000;}
public void BuildOS(){phone.PhoneOS = OperatingSystem.Symbian;}
public void BuildStylus() {phone.PhoneStylus = Stylus.No;}
public MobilePhone Phone { get {return phone;}}
public class PhoneEngineer
public void Construct(IPhoneBuilder phoneBuilder)
phoneBuilder.BuildScreen();
phoneBuilder.BuildBattery();
phoneBuilder.BuildStylus();