DEV Community

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

Collapse
 
tacsiazuma profile image
Krisztian Papp

And finally, everything in the same code base should be able to access "publicly" everything else from that same code base.

No, just please no. You really shouldn't expose everything. That's just nonsense. You should expose carefully and use the least access modifier possible in any case. If you develop a library, you shouldn't expose the whole of it for the client, because:

  • he could mess up
  • if you provide a thin interface, it's easier to understand

Also look at the top of your source files. How many import do you see? Not the whole codebase I guess. That's because when you use something then you'll start depending on it. And you don't want to depend on the whole codebase. Use private fields, private inner classes if needed. Don't let your own code to fool you or anyone else, be defensive.