Guest User

Untitled

a guest
Jan 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. public interface IFoo
  2. {
  3. bool Foo(Person a, Person b);
  4. }
  5.  
  6. public class KungFoo : IFoo
  7. {
  8. public bool Foo(Person a, Person b)
  9. {
  10. if (a.IsAmateur || b.IsAmateur) // common logic
  11. return true;
  12. return false;
  13. }
  14. }
  15.  
  16. public class KongFoo : IFoo
  17. {
  18. public bool Foo(Person a, Person b)
  19. {
  20. if (a.IsAmateur || b.IsAmateur) // common logic
  21. return false;
  22. return true;
  23. }
  24. }
  25.  
  26. public interface IFoo
  27. {
  28. bool Foo(Person a, Person b);
  29. }
  30.  
  31. public abstract class FooBase : IFoo
  32. {
  33. public bool Foo(Person a, Person b)
  34. {
  35. if (a.IsAmateur || b.IsAmateur) // common logic
  36. return true;
  37. return false;
  38. }
  39. }
  40.  
  41. public class KungFoo : IFooBase
  42. {
  43.  
  44. }
  45.  
  46. public class KongFoo : IFooBase
  47. {
  48. public override bool Foo(Person a, Person b)
  49. {
  50. // Some other logic if the common logic doesn't work for you here
  51. }
  52. }
  53.  
  54. public interface IFoo
  55. {
  56. bool Foo(Person a, Person b);
  57. }
  58.  
  59. public class KungFoo : FooImpl
  60. {
  61. public override bool Foo(Person a, Person b)
  62. {
  63. if (this.IsAmateur(a, b))
  64. return true;
  65. return false;
  66. }
  67. }
  68.  
  69. public class KongFoo : FooImpl
  70. {
  71. public override bool Foo(Person a, Person b)
  72. {
  73. if (this.IsAmateur(a, b))
  74. return false;
  75. return true;
  76. }
  77. }
  78.  
  79. public abstract class FooImpl : IFoo
  80. {
  81. public abstract bool Foo(Person a, Person b);
  82.  
  83. protected readonly Func<Person, Person, bool> IsAmateur = (a, b) => a.IsAmateur || b.IsAmateur;
  84. }
  85.  
  86. public class Person
  87. {
  88. public bool IsAmateur { get; set; }
  89. }
  90.  
  91. public abstract class IFoo{
  92. bool Foo(Person a, Person b){
  93. if (a.IsAmateur || b.IsAmateur) // common logic
  94. return true;
  95. }
  96. public abstract Object otherFooMethod(Object o);
  97. }
  98.  
  99. public class KungFoo : IFoo{
  100. //Foo already implemented
  101.  
  102. public Object otherFooMethod(Object o){
  103. return o;
  104. }
  105.  
  106. }
  107.  
  108. public class KongFoo : IFoo
  109. {
  110. public bool Foo(Person a, Person b)
  111. {
  112. if (a.IsAmateur || b.IsAmateur) // common logic
  113. return false;
  114. return !base.Foo();
  115. }
  116.  
  117. public Object otherFooMethod(Object o){
  118. return o;
  119. }
  120. }
Add Comment
Please, Sign In to add comment