Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace FactoryPattern_MobileFactory
- {
- class MainProgram
- {
- static void Main(string[] args)
- {
- MobileFactory[] factory = new MobileFactory[2];
- factory[0] = new IPhoneCreator();
- factory[1] = new AndroidCreator();
- foreach(MobileFactory creator in factory)
- {
- creator.CreateMobileDevice();
- }
- }
- }
- public abstract class MobileFactory
- {
- public abstract IMobile CreateMobileDevice();
- }
- public class IPhoneCreator : MobileFactory
- {
- public override IMobile CreateMobileDevice()
- {
- return new IPhone();
- }
- }
- public class AndroidCreator : MobileFactory
- {
- public override IMobile CreateMobileDevice()
- {
- return new Android();
- }
- }
- public interface IMobile
- {
- }
- public class IPhone : IMobile
- {
- public IPhone()
- {
- Console.WriteLine("Hello IPhone!" );
- }
- }
- public class Android : IMobile
- {
- public Android()
- {
- Console.WriteLine("Hello Android!");
- }
- }
- }
Add Comment
Please, Sign In to add comment