Abstract factory using generics I am learning design patterns and I have implemented the abstract factory using generics C#.NET. Is this implementation correct or not? Or is there any SOLID principle violation?

using System;
namespace GenericAbstractFactory
{
    public enum vehicles { car, bicycle, truck }

    interface IFourWheeler
    {
        void DriveFourWheeler();
    }

    interface ITwoWheeler
    {
        void DriveTwoWheeler();
    }

    interface IVehcileAbstractFactory&lt;VehicleTypeFactory&gt; //Abstract Factory
    {
        VehicleTypeFactory GetVehicleType();
    }

    class FourWheeler&lt;VehicleType&gt; : IVehcileAbstractFactory&lt;IFourWheeler&gt;
        where VehicleType : IFourWheeler, new() // ConcreteFactory
    {
        public IFourWheeler GetVehicleType()
        {
            return new VehicleType();
        }
    }

    class TwoWheeler&lt;VehicleType&gt; : IVehcileAbstractFactory&lt;ITwoWheeler&gt;
        where VehicleType : ITwoWheeler, new() // ConcreteFactory
    {
        public ITwoWheeler GetVehicleType()
        {
            return new VehicleType();
        }
    }

    class Car : IFourWheeler
    {
        public void DriveFourWheeler()
        {
            Console.WriteLine("Drive Car");
        }
    }

    class Truck : IFourWheeler
    {
        public void DriveFourWheeler()
        {
            Console.WriteLine("Drive Truck");
        }
    }

    class Bicycle : ITwoWheeler
    {
        public void DriveTwoWheeler()
        {
            Console.WriteLine("Drive Bicycle");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            vehicles veh = vehicles.bicycle;
            IVehcileAbstractFactory&lt;IFourWheeler&gt; getFourWheeler = null;
            IVehcileAbstractFactory&lt;ITwoWheeler&gt; getTwoWheeler = null;
            IFourWheeler actionFourWheeler = null;
            ITwoWheeler actionTwoWheeler = null;
            if (veh == vehicles.car)
            {
                getFourWheeler = new FourWheeler&lt;Car&gt;();
                actionFourWheeler = getFourWheeler.GetVehicleType();
            }
            else if (veh == vehicles.bicycle)
            {
                getTwoWheeler = new TwoWheeler&lt;Bicycle&gt;();
                actionTwoWheeler = getTwoWheeler.GetVehicleType();
            }
            else if (veh == vehicles.truck)
            {
                getFourWheeler = new FourWheeler&lt;Truck&gt;();
                actionFourWheeler = getFourWheeler.GetVehicleType();
            }
            else
            {
                throw new Exception("vehicle type not supported");
            }

            if (actionFourWheeler != null)
            {
                actionFourWheeler.DriveFourWheeler();
            }
            else if (actionTwoWheeler != null)
            {
                actionTwoWheeler.DriveTwoWheeler();
            }
            Console.Read();
        }
    }
}
I'm not sure, but I don't think a generic approach is suitable for the abstract factory pattern, because the client has to specify the concrete class type in order to call the factory, and then the whole point of that pattern is gone?

The way you've tried to implement it works, but you have effectively two parallel factories (one for four wheels, and one for two) that have nothing or just very little to do with each other (DriveFourWheeler() vs DriveTwoWheeler()).

Below I've tried to fiddle a little bit with you code in order to show my understanding of the pattern and still with a generic touch.

using System;
namespace GenericAbstractFactory
{
  public enum Vehicles { car, bicycle, truck }

  interface IWheeler
  {
    void Drive();
  }

  interface IFourWheeler : IWheeler
  {
  }

  interface ITwoWheeler : IWheeler
  {
  }

  interface IVehicleAbstractFactory
  {
    IWheeler GetVehicle();
  }

  class FourWheelerFactory&lt;FourWheeler&gt; : IVehicleAbstractFactory where FourWheeler: IFourWheeler, new()
  {
    public IWheeler GetVehicle()
    {
      return new FourWheeler();
    }
  }

  class TwoWheelerFactory&lt;TwoWheeler&gt; : IVehicleAbstractFactory where TwoWheeler: ITwoWheeler, new()
  {
    public IWheeler GetVehicle()
    {
      return new TwoWheeler();
    }
  }

  class Car : IFourWheeler
  {
    public void Drive()
    {
      Console.WriteLine("Drive Car");
    }
  }

  class Truck : IFourWheeler
  {
    public void Drive()
    {
      Console.WriteLine("Drive Truck");
    }
  }

  class Bicycle : ITwoWheeler
  {
    public void Drive()
    {
      Console.WriteLine("Drive Bicycle");
    }
  }

  class Program
  {
    static IVehicleAbstractFactory GetFactory(Vehicles vehicle)
    {
      switch (vehicle)
      {
        case Vehicles.car:
          return new FourWheelerFactory&lt;Car&gt;();
        case Vehicles.truck:
          return new FourWheelerFactory&lt;Truck&gt;();
        case Vehicles.bicycle:
          return new TwoWheelerFactory&lt;Bicycle&gt;();
      }
    }

    static void Main(string[] args)
    {
      IVehicleAbstractFactory factory = GetFactory(Vehicles.bicycle);
      IWheeler vehicle = factory.GetVehicle();
      vehicle.Drive();


      Console.Read();
    }
  }
}


I'm not saying this is the right way for the factory pattern, but may be a little clearer. The client still has to know which actual class he wants to create due to the nature of generics.