19 |
|
20 |
// 没有重复的代码 |
21 |
|
22 |
DoThingsB(); |
23 |
} |
24 |
现在我们重构含有部分相同代码的函数,用 delegate 模式重写它们: |
25 |
/// <summary> |
26 |
/// Encapsulate shared functionality |
27 |
/// </summary> |
28 |
/// <param name="action">User defined action</param> |
29 |
void UniqueWrapper(Action action) |
30 |
{ |
31 |
DoThingsA(); |
32 |
|
33 |
action(); |
34 |
|
35 |
DoThingsB(); |
36 |
} |
37 |
|