المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : factory method



C# Programming
08-12-2009, 09:04 AM
Hello All ,

I have design a factory class which will create the objects and send to the calling party. but i have small concern . Please see this code


public ElectricalDevice CreateDeviceType(int DeviceCode)
{
ElectricalDevice lobjDevice = null;


if (Convert.ToInt32(Helper.DeviceType.Fan) == DeviceCode)
{
lobjDevice = new Fan();
}
else if (Convert.ToInt32(Helper.DeviceType.Motor) == DeviceCode)
{
lobjDevice = new Motor();
}
else if (Convert.ToInt32(Helper.DeviceType.Tubelight) == DeviceCode)
{
lobjDevice = new Tubelight();
}
else
{
lobjDevice = new IronBox();
}
return lobjDevice;
}



This method is creating device and sending .

but my question is that if 2mrw i have to add some more device again i need to add more if else condition

So which pattern should i follow . Please give me some goood design links where can i have the video