@@ -7,52 +7,49 @@ It automates, what I've found to be, a very common workflow.
77
88Picture the code
99
10- -------------------------------------------------------------
11- public void DoSomething()
12- {
13-
14- SpecificMethod1(2);
15- Class1.UtilMethod("Some Text");
16- Class2.UtilMethod(64);
17- Class3.UtilMethod("More Text");
18- SpecificMethod2(256);
19- }
20- -------------------------------------------------------------
10+ public void DoSomething()
11+ {
12+ SpecificMethod1(2);
13+ Class1.UtilMethod("Some Text");
14+ Class2.UtilMethod(64);
15+ Class3.UtilMethod("More Text");
16+ SpecificMethod2(256);
17+ }
2118
2219You see that the series of calls to the Utility methods of Class1,Class2 and Class3 form a pattern which you want to reuse elsewhere.
2320
2421If you extract these 3 lines normally, you'd carry the literal params with them into the extracted method thus:
25- -------------------------------------------------------------
26- public void DoSomething()
27- {
28- SpecificMethod1(2);
29- ExtractedMethod();
30- SpecificMethod2(256);
31- }
32- private void ExtractedMethod()
33- {
34- Class1.UtilMethod("Some Text");
35- Class2.UtilMethod(64);
36- Class3.UtilMethod("More Text");
37- }
38- -------------------------------------------------------------
22+
23+ public void DoSomething()
24+ {
25+ SpecificMethod1(2);
26+ ExtractedMethod();
27+ SpecificMethod2(256);
28+ }
29+ private void ExtractedMethod()
30+ {
31+ Class1.UtilMethod("Some Text");
32+ Class2.UtilMethod(64);
33+ Class3.UtilMethod("More Text");
34+ }
35+
3936...but that's not ideal, since you now have to find and promote each of those values to a parameter of the method.
4037
4138Ideally we'd like something like...
42- -------------------------------------------------------------
43- public void DoSomething()
44- {
45- SpecificMethod1(2);
46- ExtractedMethod("Some Text", 64, "More Text");
47- SpecificMethod2(256);
48- }
49- private void ExtractedMethod(string Param0, int Param1, string Param2)
50- {
51- Class1.UtilMethod(Param0);
52- Class2.UtilMethod(Param1);
53- Class3.UtilMethod(Param2);
54- }
55- -------------------------------------------------------------
39+
40+ public void DoSomething()
41+ {
42+ SpecificMethod1(2);
43+ ExtractedMethod("Some Text", 64, "More Text");
44+ SpecificMethod2(256);
45+ }
46+ private void ExtractedMethod(string Param0, int Param1, string Param2)
47+ {
48+ Class1.UtilMethod(Param0);
49+ Class2.UtilMethod(Param1);
50+ Class3.UtilMethod(Param2);
51+ }
52+
5653...which provides a nice new method ready to be reused from other locations.
5754
5855You can use the prefious method (1x Extract + 4x Find and Promote params) or you could...
0 commit comments