3 ms·
I think there is a fundamental difference between “OOP classes” and data. Java didn’t have a way to differentiate between the two so a convention was created wi
by kaba0 4y ago
I think there is a fundamental difference between “OOP classes” and data. Java didn’t have a way to differentiate between the two so a convention was created with POJOs with properties, so reflection-based tools could use arbitrary classes in some way.
Records are imo a really great addition, making the difference explicit.
As for why private fields are important, think of a class implementing a circular buffer with a fixed-size array. Here, the start and end indices used are private state, which is a must for proper OOP — without it it couldn’t enforce class invariants.
- sandGorgon 4y agonot denying "proper OOP". my point is that a lot of code does not need it. If u were writing the exact same code in go/nodejs/python, you would get by fine without it. You would not break the contract of maliciously trying to access variables that shouldnt be accessed. For example, a popular convention is to have underscored variable names (__thisisprivate). Works perfectly OK. 99% of getters/setters dont do anything more. They do exactly this. No validation, nothing. So I'm questioning the ordinary....not the special cases.
- stickfigure 4y ago> You would not break the contract You wouldn't. Someone else would. Without fail.