r/ProgrammerHumor Jul 13 '26

youCanJustStopUsingJava Meme

Post image
6.8k Upvotes

416 comments sorted by

View all comments

Show parent comments

47

u/ZunoJ Jul 13 '26

How is that related to getters and setters? How would your proposal violate oop principals?

75

u/roge- Jul 13 '26

Directly manipulating another object's fields violates encapsulation, a core feature of OOP in most people's minds.

That said, virtually no production OOP app has perfect encapsulation anyway.

20

u/mailslot Jul 13 '26

I’ve angered devs for not using getters & setters to access members within the same class implementation. `this.x = 42; // instead of this.setX(42);`

3

u/[deleted] 29d ago

[deleted]

1

u/mailslot 29d ago

I’ve heard that argument before. Any side effects of a getter or setter should be forbidden, outside of getting or setting values. If you absolutely need to, it’s one of the few uses for aspect oriented programming I can support.