fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7.  
  8. var concreteMapperFactory = new ConcreteMapperFactory();
  9. concreteMapperFactory.GetMapper<Box>(new Box());
  10.  
  11. if (concreteMapperFactory.concreteCalled)
  12. {
  13. Console.WriteLine("Concrete called");
  14. }
  15.  
  16. if (concreteMapperFactory.templateCalled)
  17. {
  18. Console.WriteLine("Template called");
  19. }
  20. }
  21.  
  22. public interface IShape
  23. {
  24. }
  25.  
  26. public class Circle:IShape{}
  27.  
  28. public class Box: IShape{}
  29.  
  30. public abstract class AbstractMapperFactory
  31. {
  32. public abstract void GetMapper<TSource>(TSource obj) where TSource : class;
  33. }
  34.  
  35.  
  36.  
  37. class ConcreteMapperFactory: AbstractMapperFactory
  38. {
  39. public bool concreteCalled;
  40. public bool templateCalled;
  41.  
  42. public void GetMapper(Box box)
  43. {
  44. concreteCalled = true;
  45. }
  46.  
  47. public override void GetMapper<TSource>(TSource obj)
  48. {
  49. templateCalled = true;
  50. }
  51.  
  52. }}
Success #stdin #stdout 0.02s 14888KB
stdin
Standard input is empty
stdout
Template called