Bike GetBike(string Bike);
Scooter GetScooter(string Scooter);
class HondaFactory : VehicleFactory
public Bike GetBike(string Bike)
return new RegularBike();
throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", Bike));
public Scooter GetScooter(string Scooter)
return new RegularScooter();
throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", Scooter));
class HeroFactory : VehicleFactory
public Bike GetBike(string Bike)
return new RegularBike();
throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", Bike));
public Scooter GetScooter(string Scooter)
return new RegularScooter();
throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", Scooter));
return "Regular Bike- Name";
return "Sports Bike- Name";
class RegularScooter : Scooter
return "Regular Scooter- Name";
public VehicleClient(VehicleFactory factory, string type)
bike = factory.GetBike(type);
scooter = factory.GetScooter(type);
public string GetBikeName()
public string GetScooterName()
public static void Main(string[] args)
VehicleFactory honda = new HondaFactory();
VehicleClient hondaclient = new VehicleClient(honda, "Regular");
Console.WriteLine("******* Honda **********");
Console.WriteLine(hondaclient.GetBikeName());
Console.WriteLine(hondaclient.GetScooterName());
hondaclient = new VehicleClient(honda, "Sports");
Console.WriteLine(hondaclient.GetBikeName());
Console.WriteLine(hondaclient.GetScooterName());
VehicleFactory hero = new HeroFactory();
VehicleClient heroclient = new VehicleClient(hero, "Regular");
Console.WriteLine("******* Hero **********");
Console.WriteLine(heroclient.GetBikeName());
Console.WriteLine(heroclient.GetScooterName());
heroclient = new VehicleClient(hero, "Sports");
Console.WriteLine(heroclient.GetBikeName());
Console.WriteLine(heroclient.GetScooterName());