daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Oct 16th, 2018 63 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. namespace FactoryPattern_MobileFactory
  2. {
  3.   class MainProgram
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             MobileFactory[] factory = new MobileFactory[2];
  8.  
  9.             factory[0] = new IPhoneCreator();
  10.             factory[1] = new AndroidCreator();
  11.  
  12.             foreach(MobileFactory creator in factory)
  13.             {
  14.                 creator.CreateMobileDevice();
  15.             }
  16.         }
  17.     }
  18.    
  19.     public abstract class MobileFactory
  20.     {
  21.         public abstract IMobile CreateMobileDevice();
  22.     }
  23.  
  24.     public class IPhoneCreator : MobileFactory
  25.     {
  26.         public override IMobile CreateMobileDevice()
  27.         {
  28.             return new IPhone();
  29.         }
  30.     }
  31.  
  32.     public class AndroidCreator : MobileFactory
  33.     {
  34.         public override IMobile CreateMobileDevice()
  35.         {
  36.             return new Android();
  37.         }
  38.     }
  39.    
  40.     public interface IMobile
  41.     {
  42.     }
  43.  
  44.     public class IPhone : IMobile
  45.     {
  46.         public IPhone()
  47.         {
  48.             Console.WriteLine("Hello IPhone!" );
  49.         }
  50.     }
  51.  
  52.     public class Android : IMobile
  53.     {
  54.         public Android()
  55.         {
  56.             Console.WriteLine("Hello Android!");
  57.         }
  58.     }
  59.    
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top