Pass things to the constructor that are immutable properties of the object. Whenever possible, make all the properties of an object immutable. In full, this allows you to completely destroy the object.
The immutable properties assigned during construction avoid various race conditions (especially in multi-threaded environments) and help to ensure that the object is always consistent, which eliminates the possibility of many errors. By forcing properties to be defined during construction, you avoid extensive error checking code. As soon as the entire object can be immutable, there is scope for exchanging equivalent objects, which improves memory performance.
If the parameter is not an immutable property of the object, then its purpose in the constructor is just a convenience. In general, it should be appointed by the installer to reduce code complexity (since a setter is required anyway). If the constructor is called very often, then the convenience of the parameter may be worth this additional complexity.
source share