Best practice access modifier in C # vs Java

I understand that the rule of thumb in OOD minimizes access to all members of a given object as much as possible.

C # and Java seem to implement the same set of access modifiers; however, something that puzzled me for some time is why Java classes seem to be mostly declared publicly available, and C # classes are generally considered the default. Is there any subtlety for these languages ​​that imposes these differences, or is it just a matter of agreement or what?

I often review my C # code (I usually make most classes publicly available, with the exception of inner classes, anonymous classes, and other classes with a narrow scope and utility) in an attempt to please the compiler, however, I wonder if I can do something important.

+5
source share
4 answers

Java's scope is slightly different from C # scoping .

This is briefly stated in C # From the perspective of Java Developer. The same, but different: Access modifiers . This document is a bit outdated now, but it still mostly matters.

There are two errors in this list:

  • # internal Java ( ).
  • # internal protected Java protected.

, , , /.

, # . Java - , .

+6

, . : " , ". Java

+5

, , / , . , getXXX() setXXX(), . setXXX() . - , , .

+1

"" ( ) , ... . :

" , ". ~

0

All Articles