Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #3022

Re: Why only public methods on interfaces?

From Tom Anderson <twic@urchin.earth.li>
Newsgroups comp.lang.java.programmer
Subject Re: Why only public methods on interfaces?
Date 2011-04-10 18:10 +0100
Organization Stack Usenet News Service
Message-ID <alpine.DEB.2.00.1104101751060.14871@urchin.earth.li> (permalink)
References <25875c94-9af2-4d28-976d-2050a738ae2e@n10g2000yqf.googlegroups.com> <proxy-20110408031832@ram.dialup.fu-berlin.de> <private-interface-20110409144520@ram.dialup.fu-berlin.de> <interface-20110410183518@ram.dialup.fu-berlin.de>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Sun, 10 Apr 2011, Stefan Ram wrote:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>> A proxy could use several interfaces, one for public methods,
>>> one for private methods. But »private« to whom?
>> I want to give an example for what I was thinking about:
>
>  Two compilets (aka SSCCEs):
>
>  First: Make some methods of the interface callable only from
>  a certain scope in a way so that calls from other scopes
>  will be refuted already at compile time.
>
>  [snip]
>
> public class Main
> { public static void main( final java.lang.String[] args )
>  {
>    /* Can't get direct access to method( Key ) from here. */

Yes you can:

      publicInterface.method(null);

For this technique to be effective, there has to be a null check in the 
method. Even then, it will be a runtime error, not a compile-time error, 
when it is called from outside the intended scope.

Your second technique does work, though, because it requires the caller to 
be able to provide an instance of the hidden Acceptor type. Another way of 
using that, which i think gives you static safety, is:

public class PublicFace {
 	public class PrivateFace { // intended private
 		public void secret() {}
 	}
 	private PrivateFace hyde = new PrivateFace();
 	private static class Extractor {
 		public static final Extractor THIS = new Extractor();
 		public PrivateFace extract(PublicFace jekyll) {
 			return jekyll.hyde;
 		}
 	}

 	public static void insider(PublicFace jekyll) {
 		Extractor.THIS.extract(jekyll).secret();
 	}
}

public class Main {
 	public static void outsider(PublicFace jekyll) {
 		// i claim that there is no way to write an expression of type Extractor here
 		// without that, you cannot possibly extract hyde from jekyll
 	}
}

tom

-- 
I am the best at what i do.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

Why only public methods on interfaces? kramer31 <kramer.newsreader@gmail.com> - 2011-04-07 17:09 -0700
  Re: Why only public methods on interfaces? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-04-07 21:48 -0300
  Re: Why only public methods on interfaces? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-07 21:01 -0400
    Re: Why only public methods on interfaces? v_borchert@despammed.com (Volker Borchert) - 2011-04-08 02:43 +0000
      Re: Why only public methods on interfaces? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-08 00:24 -0400
  Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-07 21:49 -0700
    Re: Why only public methods on interfaces? Owen Jacobson <angrybaldguy@gmail.com> - 2011-04-08 01:01 -0400
      Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-07 22:37 -0700
        Re: Why only public methods on interfaces? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-08 00:14 -0700
          Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-08 06:59 -0700
            Re: Why only public methods on interfaces? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-08 07:17 -0700
              Re: Why only public methods on interfaces? Patricia Shanahan <pats@acm.org> - 2011-04-08 08:59 -0700
                Re: Why only public methods on interfaces? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-04-08 17:27 -0700
                Re: Why only public methods on interfaces? "Mike Schilling" <mscottschilling@hotmail.com> - 2011-04-09 22:14 -0700
                Re: Why only public methods on interfaces? "Mike Schilling" <mscottschilling@hotmail.com> - 2011-04-09 22:28 -0700
                Re: Why only public methods on interfaces? Tom Anderson <twic@urchin.earth.li> - 2011-04-10 16:02 +0100
  Re: Why only public methods on interfaces? Roedy Green <see_website@mindprod.com.invalid> - 2011-04-08 03:18 -0700
    Re: Why only public methods on interfaces? Esmond Pitt <esmond.pitt@bigpond.com> - 2011-04-08 20:32 +1000
  Re: Why only public methods on interfaces? Tom Anderson <twic@urchin.earth.li> - 2011-04-08 20:34 +0100
  Re: Why only public methods on interfaces? Tom Anderson <twic@urchin.earth.li> - 2011-04-10 18:10 +0100

csiph-web