_ at the beginning of the property to signify that we don’t want that value changed directly.
However sometimes you do want that value to be changed to specific values, hence you create a
setter method. This setter method is typically the same wording as the property just without the underscore, hence us having the property
_numOfSensors vs the setter
numOfSensors. If we didn’t use the underscore, then people would try to use the setter and instead directly change the value of the property, bypassing all our built in validation to prevent this.
Therefore by keeping them different, you use the setter method to set the value i.e.,
robot.numOfSensors = 100, and that way we can make sure that the user follows our validation rules, in this case making sure it is a positive integer.
robot.numOfSensors instead of
robot._numOfSensors allows us to add validation, ensuring that the property is not changed to an invalid value e.g,
robot._numOfSensors = "hello" works,
robot.numOfSensors = "hello" will not.