Created
April 11, 2014 05:18
-
-
Save mausch/10442035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyOld5700LoCBusinessClass { // actually 5715 lines | |
bool flag1, flag2, ..., flag15; | |
string message1, message2, ... message15; | |
// more instance variables | |
void Method1() {...} | |
... | |
void Method30() {...} | |
void Method31() { | |
// 1000 lines of code mutating many instance variables and reading others. Grossly simplified here to illustrate the concept. | |
flag4 = true; | |
flag6 = false; | |
message4 = "hello"; | |
if (flag5) message5 = "byebye"; | |
} | |
// more methods | |
} | |
Refactor Method31 to: | |
static void Method31(bool flag5, out bool flag4, out bool flag6, out string message4, ref string message5) { | |
flag4 = true; | |
flag6 = false; | |
message4 = "hello"; | |
if (flag5) message5 = "byebye"; | |
} | |
void Method31() { | |
Method31(flag5: flag5, flag4: out flag4, flag6: out flag6, message4: out message4, message5: ref message5); | |
} | |
Now I can tell more precisely which instance variables Method31 uses and how (read/write) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Huh. I see. It seems you have to deal with a really awful codebase :(