0

What is importance of the setter ang getter.

Confuse😖

18th Sep 2020, 10:32 AM
Dennis Albonia
Dennis Albonia - avatar
4 ответов
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.
18th Sep 2020, 10:47 AM
Ipang
+ 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
18th Sep 2020, 10:39 AM
Namit Jain
Namit Jain - avatar
+ 2
Which language?
18th Sep 2020, 10:33 AM
Namit Jain
Namit Jain - avatar
0
Namit Jain all language
18th Sep 2020, 10:35 AM
Dennis Albonia
Dennis Albonia - avatar