Using a Class Variable vs Sending Local Variable to Functions/Methods

后端 未结 3 1207
太阳男子
太阳男子 2021-01-12 04:49

When is it good form to push a local variable to a function/method as a parameter, rather than using a class variable in place of the function/method variable.

For i

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 05:04

    I look at it in terms of dependency, i.e. who is dependent on the variable (in your case var), is it a method or a class?

    For e.g. JavaBeans have class variables that are dependent by the class, so if the class needs these variables then DoSomething() is best.

    Alternatively, if you class doesn't care about var and doesn't need it anywhere else, and only DoSomething() requires var, then DoSomething(int var) is essential.

提交回复
热议问题