Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use private members - when to pass as function/method parameter [closed]

I often found myself when writing a new class that inside a class I pass a parameter inside of many private methods. On the other side I also create sometime private members and just use them in one method.

So my question is "After which rules do you create a private member and when you don't and pass the variable from private method to private method"?

Can you give me some simple tips or hints, so that the design will get better?

like image 748
nWorx Avatar asked Dec 02 '22 07:12

nWorx


1 Answers

If a parameter is part of the 'state' of the class, then use a private member. If on the other hand the parameter is just a temporary object, just pass it as a parameter.

like image 165
kgiannakakis Avatar answered Dec 05 '22 17:12

kgiannakakis