Discussion on: What is the difference between public, protected, and private in Java?

xowap profile image
Rémy 🤖

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.

Thread Thread
fpuffer profile image
Frank Puffer

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?