Tag Archives: Getters and Setters

Getters and Setters

Getters and Setters are used to effectively protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. Getters and setters are also known as accessors and mutators, respectively.

Accessing properties directly is not a good practice.

Sometimes we need to check the value in case of an invalid input, or do some other data validation or calculation before assigning or accessing the property value.

Continue reading Getters and Setters

Follow and like us: