code_junkie

How to refactor: split a class into two which communicate via an interface

Nov 11th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class PresenterAndController
  2. {
  3. public void Control()
  4. {
  5. Present();
  6. }
  7.  
  8. public void Present()
  9. {
  10. // present something
  11. }
  12. }
  13.  
  14. internal class Presenter
  15. {
  16. public void Present()
  17. {
  18. // present something
  19. }
  20. }
  21.  
  22. class PresenterAndController : Presenter
  23. {
  24. public void Control()
  25. {
  26. Present();
  27. }
  28. }
  29.  
  30. internal class Presenter
  31. {
  32. public void Present()
  33. {
  34. // present something
  35. }
  36. }
  37.  
  38. class PresenterAndController : Presenter
  39. {
  40. private Presenter myPresenter;
  41.  
  42. public void Present() // hides base method
  43. {
  44. myPresenter.Present();
  45. }
  46.  
  47. public void Control()
  48. {
  49. Present(); // it now references method from this type
  50. }
  51. }
Add Comment
Please, Sign In to add comment