loading...

re: What is the difference between public, protected, and private in Java? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Well I would have agreed a few years ago but now I've been coding in many languages and it appears that this strategy isn't really useful in my opi...
 

How can the IDE tell me about mistakes in this case? When everything is public there are no access related mistakes.

 

Well private fields are private because you don't want to guarantee internal structure to outsiders so if you change it other apps don't get broken.

Here if you change something you're going to break the compilation so you're basically going to notice that you've broken your app/lib. Thus you are pretty safe.

While this makes sense, I still don't get your point.

If I understand you correctly, you suggest to make all fields and methods of a class public because encapsulation does not provide much value.

This means that every part of your codebase is potentially directly connected to any other part. How do you keep the design from turning into a Big Ball of Mud? You mention interfaces. But how do you make sure everybody uses them and does not access the classes directly?

code of conduct - report abuse