posted 8 years ago
I would prefer the first option. You have no idea what prop is equal to when it is passed to your constructor but you immediately set this.prop equal to it. Maybe this isn't an issue, but lets say that you are expecting prop to be between 0 and 500 or some other constraint. By passing the value to setProp() method you can check the value to make sure it is valid before setting this.prop equal to it. Yes, you could do the same thing in your constructor but if setProp() is a public method then you will have duplicate code which is always frowned upon. Assuming you don't care what prop is and/or your setProp() method is either not public or contains no logic then either choice is fine.... otherwise option 1 is the best IMHO.