Guest User

Untitled

a guest
Dec 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. abstract class MyBase {
  2. protected abstract void CustomLogic(); // Subclasses implement this
  3. public void PayloadMethod() {
  4. ... // Do somethig
  5. CustomLogic();
  6. ... // Do something else
  7. }
  8. }
  9.  
  10. class Derived1 : MyBase {
  11. protected override void CustomLogic() {
  12. ... // Custom logic 1
  13. }
  14. }
  15.  
  16. class Derived2 : MyBase {
  17. protected override void CustomLogic() {
  18. ... // Custom logic 2
  19. }
  20. }
  21.  
  22. class Derived3 : MyBase {
  23. protected override void CustomLogic() {
  24. ... // Custom logic 3
  25. }
  26. }
  27.  
  28. abstract class Foo
  29. {
  30. public void Bar()
  31. {
  32. // some code defined in the parent class
  33.  
  34. BarCore(); // the customized part of it as defined in the child class
  35. }
  36.  
  37. protected virtual void BarCore() { }
  38. }
  39.  
  40. class BaseClass
  41. {
  42. public void DoSomething()
  43. {
  44. // base class code
  45.  
  46. // derived class code, modifiable by the derived class
  47. this.DoItSpecificallyForThatDerivedClass();
  48. }
  49.  
  50. protected abstract void DoItSpecificallyForThatDerivedClass();
  51. }
  52.  
  53. public class ADerivedClass : BaseClass
  54. {
  55. protected override void DoItSpecificallyForThatDerivedClass()
  56. {
  57. // code specific to this instance and/or class
  58. }
  59. }
Add Comment
Please, Sign In to add comment