Improved introduction of getter and setter (#22337)

Mentioned the principle of data encapsulation
pull/34314/head
Nicola Iacovelli 2018-11-13 00:07:16 +01:00 committed by Manish Giri
parent 54b41a3cd0
commit 0d762bda39
1 changed files with 1 additions and 1 deletions

View File

@ -3,7 +3,7 @@ title: Getters & Setters
--- ---
# Getters & Setters # Getters & 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. Getters and Setters are used to implement the principle of encapsulation and so the instance variable can be accessed only by its getter and setter methods. 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.
By convention, getters start with `get`, followed by the variable name, with the first letter of the variable name capitalized. Setters start with `set`, followed by the variable name, with the first letter of the variable name capitalized. By convention, getters start with `get`, followed by the variable name, with the first letter of the variable name capitalized. Setters start with `set`, followed by the variable name, with the first letter of the variable name capitalized.