2
Answers

Factory pattern

Photo of Hemanth Raj

Hemanth Raj

7y
855
1
Hi What is Factory Pattern anyone know could you explain in simple with real time example....

Thank you

Answers (2)

1
Photo of Vivek Kumar
157 11.8k 5.7m 7y
Have a look into the below links. This is explained in detailed with real time example.
 
http://www.c-sharpcorner.com/article/factory-method-design-pattern-in-c-sharp/
 
http://www.dofactory.com/net/factory-method-design-pattern
 
http://www.dotnettricks.com/learn/designpatterns/factory-method-design-pattern-dotnet 
0
Photo of Vijay Kumar
NA 240 33 7y
enum FanType {     TableFan,     CeilingFan,     ExhaustFan }  interface IFan {     void SwitchOn();     void SwitchOff(); }  class TableFan : IFan {.... }  class CeilingFan : IFan {.... }  class ExhaustFan : IFan {..... }  interface IFanFactory {     IFan CreateFan(FanType type); }  class FanFactory : IFanFactory {     public IFan CreateFan(FanType type)     {         switch (type)         {             case FanType.TableFan:                 return new TableFan();             case FanType.CeilingFan:                 return new CeilingFan();             case FanType.ExhaustFan:                 return new ExhaustFan();             default:                 return new TableFan();         }     } }  //The client code is as follows:  static void Main(string[] args) {         IFanFactory simpleFactory = new FanFactory();         // Creation of a Fan using Simple Factory         IFan fan = simpleFactory.CreateFan(FanType.TableFan);         // Use created object         fan.SwitchOn();          Console.ReadLine();  }