J
Jim Cobban
I am a bit puzzled by the way that interfaces are defined. As I read it all
members of an interface are public by definition and it is even discouraged
to bother specifying public since it is the only possible value. So either
an entire interface is public, and therefore part of the contract between
the package and the outside world, or else the entire interface is package
level access.
If I have understood this correctly, this is a pain in the butt. I have a
class that provides services some of which are used only within the package
and others that may be provided to other packages. Both internal and
external users access these services through an interface, not by
referencing the class itself, because they do not care about the internal
implementation of the class and therefore do not need to be recompiled if I
change the internal implementation. Using an interface also eliminates
circular references.
However Java will not permit me to define some of the methods in an
interface to be public access and others package access. This in turn
prevents me from defining the actual implementations as package access.
Peculiarly although to my mind I am trying to define stronger security on
those methods Java complains about "weaker" access. That language is
strange: Would you say a locked room labelled "authorized personel only" has
"weaker" access than one that is publicly accessable?
I suppose I could define two distinct interfaces, one public and one
package, that would both be implemented by my class, but then any other
member of my package that needed to access both the public and package level
interface of the class would need to cast back and forth.
How do others define their package interfaces so as to make what they want
public while hiding what the outside world does not need to see?
--
Jim Cobban (e-mail address removed)
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438
members of an interface are public by definition and it is even discouraged
to bother specifying public since it is the only possible value. So either
an entire interface is public, and therefore part of the contract between
the package and the outside world, or else the entire interface is package
level access.
If I have understood this correctly, this is a pain in the butt. I have a
class that provides services some of which are used only within the package
and others that may be provided to other packages. Both internal and
external users access these services through an interface, not by
referencing the class itself, because they do not care about the internal
implementation of the class and therefore do not need to be recompiled if I
change the internal implementation. Using an interface also eliminates
circular references.
However Java will not permit me to define some of the methods in an
interface to be public access and others package access. This in turn
prevents me from defining the actual implementations as package access.
Peculiarly although to my mind I am trying to define stronger security on
those methods Java complains about "weaker" access. That language is
strange: Would you say a locked room labelled "authorized personel only" has
"weaker" access than one that is publicly accessable?
I suppose I could define two distinct interfaces, one public and one
package, that would both be implemented by my class, but then any other
member of my package that needed to access both the public and package level
interface of the class would need to cast back and forth.
How do others define their package interfaces so as to make what they want
public while hiding what the outside world does not need to see?
--
Jim Cobban (e-mail address removed)
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438