I believe this is language agnostic question - if it's not then please correct me.
Let's say I have a class (code snippet is a kind of 'pseudo code')
class Car:
private steering_wheel
private engine
public Car(steering_wheel, engine):
this.steering_wheel = steering_wheel
this.engine = engine
public void service():
clean_steering_wheel()
repair_engine()
private void clean_steering_wheel():
this.steering_wheel.do_stuff()
private void repair_engine():
this.engine.do_stuff()
which works well! But I could also change private methods a bit and let them use fields (i.e steering_wheel
and engine
) via arguments, not directly
class Car:
private steering_wheel
private engine
public Car(steering_wheel, engine):
this.steering_wheel = steering_wheel
this.engine = engine
public void service():
clean_steering_wheel(this.steering_wheel)
repair_engine(this.engine)
private void clean_steering_wheel(steering_wheel):
steering_wheel.do_stuff()
private void repair_engine(engine):
engine.do_stuff()
Let's assume that all parameters(arguments) are passed by reference.
What are the advantages and disadvantages of these solutions? Which is considered as better practice? Which one do you prefer?