Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public class Original
  2. {
  3. public string OldFunction(string s1, string s2)
  4. {
  5. return s1 + s2;
  6. }
  7. }
  8.  
  9.  
  10. public class RobertsSolution
  11. {
  12. // this potentially breaks old code unless new params are optional.
  13. // but raises concerns around ensuring validity of inputs.
  14. public string OldFunction(string s1, string s2, string newParam)
  15. {
  16. // this increases code complexity for all code paths
  17. // function gets longer and longer and longer and longer
  18. if (newParam != null)
  19. {
  20. s2 = newParam;
  21. }
  22.  
  23. return s1 + s2;
  24. }
  25. }
  26.  
  27.  
  28. public class DansSolution
  29. {
  30. public string OldFunction(string s1, string s2)
  31. {
  32. return s1 + s2;
  33. }
  34.  
  35.  
  36. // this increases code complexity only for new code path
  37. // plus, the increase in complexity is smaller because there is no branching
  38. public string NewFunction(string newParam)
  39. {
  40. string s1 = null; // default value
  41. return OldFunction(s1, newParam);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement