3 ms·
getters and setters prevent other objects from modifying internal properties in unexpected ways. Having that encapsulation and abstraction is important for main
by jorblumesea 5y ago
getters and setters prevent other objects from modifying internal properties in unexpected ways. Having that encapsulation and abstraction is important for maintainable code.
Also, getters and setters don't always modify individual values. Imagine a class where we have:
private val firstName
private val lastName
fun returnFullName():
return firstName + lastName
- grishka 5y ago> modifying internal properties in unexpected ways Except I'm talking about Java classes that store data. They don't do any operations on it, they don't have any internal state, they're more like C structs. > Also, getters and setters don't always modify individual values. Of course. But one doesn't contradict the other.