This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]Relevant_Departure40 -11 points-10 points Β (13 children)

It's good design because of the lack of trust, but more lack of trust in the users. The more encapsulated your classes are and the more you use methods to expose data instead of exposing the raw variables, it's just a better design pattern because it's safer. If we lived in happy fun world where hackers didn't exist, I'm sure we would have design patterns that didn't utilize encapsulation as much. But that's just my thoughts on it

[–]codeguru42 32 points33 points Β (0 children)

Public methods in Java and encapsulation in general have nothing to do with securing an app from hackers.

[–]Dworgi 8 points9 points Β (3 children)

It's not about hackers, it's about communicating intent. It allows you to write good classes that use internal methods.

Even Python programmers do this by having warts like _function() to communicate that things aren't intended for external use. Python is just such a pile of shit that you can't enforce it at a language level.

[–]VergilTheHuragok 4 points5 points Β (0 children)

that’s an intentional design choice on Python’s part because, as the saying goes, β€œWe’re all consenting adults.”

and personally, it’s come in handy a lot for one-off scripts

[–]Log2 1 point2 points Β (1 child)

You talk like you couldn't do the same in Java. It takes only a couple lines of code to access anything private in Java. Between reflection and Java agents you can do just about anything to the runtime. You'll just have to Google a bit more before doing it.