Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you use the default (package) visibility in Java? [closed]

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?

like image 345
Miquel Avatar asked Dec 05 '12 15:12

Miquel


1 Answers

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.

like image 118
Hermann Hans Avatar answered Nov 07 '22 00:11

Hermann Hans