Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. public abstract class FactoryBase
  2. {
  3. public abstract Product FactoryMethod(int type);
  4. }
  5.  
  6. public class ConcreteFactory : FactoryBase
  7. {
  8. public override Product FactoryMethod(int type)
  9. {
  10. switch (type)
  11. {
  12. case 1:
  13. return new ConcreteProduct1();
  14.  
  15. case 2:
  16. return new ConcreteProduct2();
  17.  
  18. default:
  19. throw new ArgumentException("Invalid type.", "type");
  20. }
  21. }
  22. }
  23.  
  24. public abstract class ProductBase { }
  25.  
  26. public class ConcreteProduct1 : ProductBase { }
  27.  
  28. public class ConcreteProduct2 : ProductBase { }
Add Comment
Please, Sign In to add comment