在Clean Code book 中有一种观点认为,最佳实践是使用没有传入和传出参数的函数。所以我的问题是,使用相互传递 args 的函数或共享和操作静态对象的 void 函数更有意义?
例子:
选项1。
public List<MyThing> FunctionA(List <MyThing> myThings){
myThings.Add(SomeBlah);
return myThings;
}
public void FunctionB(){
List<MyThing> myThings = new List<MyThing>();
myThings = InitiateThingsOrWhatever();
List<MyThing> myChangedThings = FunctionA(myThings);
}
选项 2:
private static List<MyThing> _myThings = new List<MyThing>();
public static List<MyThing> MyThings{
get { return _myThing; }
set { _myThing = value; }
}
public void SomeFunction(){
FunctionA();
FunctionB();
}
public void FunctionA(){
MyThings = YadaYadaStuff();
}
public void FunctionB(){
var showMyChangedThings = MyThings;
}