Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Original
- {
- public string OldFunction(string s1, string s2)
- {
- return s1 + s2;
- }
- }
- public class RobertsSolution
- {
- // this potentially breaks old code unless new params are optional.
- // but raises concerns around ensuring validity of inputs.
- public string OldFunction(string s1, string s2, string newParam)
- {
- // this increases code complexity for all code paths
- // function gets longer and longer and longer and longer
- if (newParam != null)
- {
- s2 = newParam;
- }
- return s1 + s2;
- }
- }
- public class DansSolution
- {
- public string OldFunction(string s1, string s2)
- {
- return s1 + s2;
- }
- // this increases code complexity only for new code path
- // plus, the increase in complexity is smaller because there is no branching
- public string NewFunction(string newParam)
- {
- string s1 = null; // default value
- return OldFunction(s1, newParam);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement