求问,像这种多个内部方法都有相同参数 config,有没有办法做一些抽取,让 fun1/2/3/4 只保留自己的参数,总觉得每个方法参数都有 config 蛮蠢的。。。
================================================================
import org.springframework.stereotype.Component;
@Component
public class TestService {
public void handle() {
Config config = init();
fun1(config, 1);
fun2(config, "t");
fun3(config, 0D);
fun4(config);
}
private Config init() {
// ...
}
private void fun1(Config config, Integer i) {
// ...
}
private void fun2(Config config, String s) {
// ...
}
private void fun3(Config config, Double d) {
// ...
}
private void fun4(Config config) {
// ...
}
}