0
What is importance of the setter ang getter.
Confuse😖
4 Respuestas
0
In relation to encapsulation:
Implementation of a getter allows outsiders to read a member's data, while keeping the member's accessibility scope private, to prevent unauthorised modification of the said member.
Implementation of a setter allows outsiders to write/modify a private member's data. Restriction of new data can also be applied in a setter to ensure that the new data is of an expected type or value, forcing the new data to be valid.
+ 3
Dennis Albonia Many languages have a shorter method!
Ruby:
attr_accessor: name
Python:
Very automatic 😍 no need! Ya, for private variables you might need a setter (getter is still automatic 🙌)
Java:
For private variables you will have to define complete methods as getters and setters (a lengthy process)! But there's no restriction on public/static/protected variables!
C:
There's no OOP😆
C++:
Donno
+ 2
Which language?
0
Namit Jain all language