At first, we have a working function name foo
void foo() {
bar1(9);
bar2(9);
}
Noted that the value 9
is hard-coded. Then, we want to make a change so we can make 9
a parameter yet preserving the old foo
function, so we change it to
void foo() {
foo_ex(9);
}
void foo_ex(int x) {
bar1(x);
bar2(x);
}
Coding-wise, this is usually done by one way of following
- Replacing the line
void foo()
tovoid foo_ex(int x)
and then re-createfoo
function that in turns callfoo_ex
- Declaring a new
foo_ex
function, move the body offoo
function tofoo_ex
and replacing hard-coded value with parameterx
, and then callfoo_ex
fromfoo
The question is, is there any name for this pattern? It is not a complex pattern but I usually take some time to communicate this and the pattern arises quite often.
foo_ex
with different values? Otherwise I would call this "unnecessary."