Posts

Showing posts with the label Getter

Getter and Setter in C++

Image
Getter and Setter:            Getters and setters  are used to efficiently protect your data. This is a technique used greatly when creating classes.  For each instance variable, a  getter  method returns its value while a  setter  method sets or updates its value. The  getter  method returns the value of the attribute. The  setter  method takes a parameter and assigns it to the attribute. The  getters and setters  are usually public and the variables are made. Why use getter and setter: Getters and setters  makes your code more manageable and more future proof.  If you ever want to change the class, and you want to drop the field, you can emulate it and your application code is not broken.  You will be helpful in large projects. Consuming class would be more homogeneous. ☝ Getters and Setters are a common technique used in object oriented programming. It is good practice to use thes...