Is there anything wrong with this?
namespace WindowsFormsApplication1
{
public interface ICarfactory
{
ICar getCar(CarType carType);
}
public interface ICar
{
}
public class Sedan: ICar
{
}
public class Hatchback : ICar
{
}
public class SUV : ICar
{
}
public class HondaSUV : SUV
{
}
public class HondaSedan : Sedan
{
}
public class HondaHatchback : Hatchback
{
}
public class HyundaiSUV : SUV
{
}
public class HyundaiSedan : Sedan
{
}
public class HyundaiHatchback : Hatchback
{
}
public class MarutiHatchback : Hatchback
{
}
public class MarutiSUV : SUV
{
}
public class MarutiSedan : Sedan
{
}
public class Hyundai : ICarfactory
{
public ICar getCar(CarType carType)
{
switch (carType)
{
case CarType.Sedan:
return new HyundaiSedan();
case CarType.HatchBack:
return new HyundaiHatchback();
case CarType.SUV:
return new HyundaiSUV();
default:
return null;
}
}
}
public class Maruti : ICarfactory
{
public ICar getCar(CarType carType)
{
switch (carType)
{
case CarType.Sedan:
return new MarutiSedan();
case CarType.HatchBack:
return new MarutiHatchback();
case CarType.SUV:
return new MarutiSUV();
default:
return null;
}
}
}
public class Honda : ICarfactory
{
public ICar getCar(CarType carType)
{
switch (carType)
{
case CarType.Sedan:
return new HondaSedan();
case CarType.HatchBack:
return new HondaHatchback();
case CarType.SUV:
return new HondaSUV();
default:
return null;
}
}
}
public enum CarType
{
Sedan,
HatchBack,
SUV
}
}
private void button4_Click(object sender, EventArgs e)
{
ICar myCar;
ICarfactory carfactory;
carfactory = new Hyundai();
myCar = carfactory.getCar(CarType.SUV);
myCar = carfactory.getCar(CarType.HatchBack);
myCar = carfactory.getCar(CarType.Sedan);
carfactory = new Honda();
myCar = carfactory.getCar(CarType.SUV);
myCar = carfactory.getCar(CarType.HatchBack);
myCar = carfactory.getCar(CarType.Sedan);
carfactory = new Maruti();
myCar = carfactory.getCar(CarType.SUV);
myCar = carfactory.getCar(CarType.HatchBack);
myCar = carfactory.getCar(CarType.Sedan);
}