Default visibility in java means only other classes in the same java package can access it. I certainly see the use of it, and have used it in several occasions.
On the other hand, 90% of the default visibility I encounter is simply from a developer that forgot to add any visibility keyword.
So, on the one hand, there's legitimate uses, on the other, it often masks bad code. What do you do in your development teams?
I generally try to get everyone to start with the most limited scope and only start to expand outward if we see that it's necessary in the design. Occasionally the decision to move from private
to package-private
is also driven by our need to write tests without having to go down the route of using a mocking framework (see Powermock).
To add to this, we follow the same mentality on mutability. Everything starts out as final
and only as we see the need to modify state do we remove it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With