My Product Factory
public interface IProductFactory
{
void Drive(int miles);
}
My Vehicle Factory
public interface IVehicleFactory
{
IProdctFactory GetVehicle(string Vehicle);
}
Product Bike
class Bike:IProdctFactory
{
public void Drive(int miles)
{
Console.WriteLine("Drive the Bike : " + miles.ToString() + "km");
}
}
Product Scooter
class Scooter:IProdctFactory
{
public void Drive(int miles)
{
Console.WriteLine("Drive the Scooter : " + miles.ToString() + "km");
}
}
Product Car
class Car:IProdctFactory
{
public void Drive(int miles)
{
Console.WriteLine("Drive the Car : " + miles.ToString() + "km");
}
}
Product Jeep
class Jeep:IProdctFactory
{
public void Drive(int miles)
{
Console.WriteLine("Drive the Jeep : " + miles.ToString() + "km");
}
}
Two Wheeler Factory
public class TwoWheelerFactory : IVehicleFactory
{
public IProdctFactory GetVehicle(string Vehicle)
{
switch (Vehicle)
{
case "Scooter":
return new Scooter();
case "Bike":
return new Bike();
default:
throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", Vehicle));
}
}
}
Four Wheeler Factory
class FourWheelerFactory:IVehicleFactory
{
public IProdctFactory GetVehicle(string Vehicle)
{
switch (Vehicle)
{
case "Car":
return new Car();
case "Jeep":
return new Jeep();
default:
throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", Vehicle));
}
}
}
Client
class Program
{
static void Main(string[] args)
{
IVehicleFactory twoWheelerfactory = new TwoWheelerFactory();
IProdctFactory scooter = twoWheelerfactory.GetVehicle("Scooter");
scooter.Drive(10);
IProdctFactory bike = twoWheelerfactory.GetVehicle("Bike");
bike.Drive(20);
IVehicleFactory fourWheelerFactory = new FourWheelerFactory();
IProdctFactory car = fourWheelerFactory.GetVehicle("Car");
car.Drive(100);
IProdctFactory jeep = fourWheelerFactory.GetVehicle("Car");
jeep.Drive(200);
Console.ReadKey();
}
}
Is having two concrete vehicle class (TwoWheelerFactory, FourWheelerFactory) ok in factory pattern?
Though I read a lot about abstract factory pattern, I am still not sure about what it is :( Can someone help me to convert this as Abstract Factory pattern?
I read
Design Patterns: Abstract Factory vs Factory Method
and
http://www.dotnet-tricks.com/Tutorial/designpatterns/FUcV280513-Factory-Method-Design-Pattern---C