title: How show only a view of an interface in java
body: <p>Is it possible to show only a particular view of an interface or approximate this behavior in Java? For example:</p>
  
  <pre><code>public interface SecureDevice
  {
     bool connectWith( SecureDevice d ); // visible to people who have a SecureDevice object
     bool connectWith( SecureDevice d, Authentication a ); // somehow only visible to classes with permission
  }
  </code></pre>
  
  <p>I would like users of the SecureDevice interface to have no idea that an authentication needs to occur for the interaction to occur or even that the class Authentication exists. They don't need to know the details. They only need to know that the interaction either happened or didn't. For example, a user who obtained two SecureDevice objects might try this:</p>
  
  <pre><code>public void establishConnection(SecureDevice d1, SecureDevice d2 )
  {
  
      Connector c = new Connector();
  
      if( false == d1.connectWith( d2 ) )
      {
          System.out.println("Couldn't connect to directly");
      }
      else if ( false == c.connect( d1, d2 ) )
      {
          System.out.println("Couldn't connect using Connector.");
      }
   }
  </code></pre>
  
  <p>but I might define a class like this:</p>
  
  <pre><code>public class Computer implements SecureDevice
  {
      private Authentication auth;
  
      public bool connectWith( SecureDevice d )
      {
          return d.connectWith(d, auth);
      }
  
      private? bool connectWith(SecureDevice d, Authorization a)
      {
          // check the authorization, do whatever it takes to connect, etc.
      }
  }
  </code></pre>
  
  <p>or similarly</p>
  
  <pre><code>public class Connector 
  {
      private Authentication myAuth;
  
      public bool connect(SecureDevice a, SecureDevice b)
      {
          a.connectWith(b, myAuth);
      }
  
  }   
  </code></pre>
  
  <p>This example seems akin friends in C++, however I feel like it is slightly different. I don't want to give special permission to use a method.</p>
  
  <p>I would like to have two interfaces as part of SecureDevice:</p>
  
  <pre><code>   public interface SecureDevice
     {
         public interface UserView
         {
             connectWith(SecureDevice d);
         }
  
         public interface LibraryView
         {
             connectwith(SecureDevice d, Authentication a);
         }
      }
  </code></pre>
  
  <p>If there really were two separate interfaces, I would have to cast between them when I wanted to use the other interface, and I wouldn't be able to gurantee that an object implementing one actually implemented the other, so I'd have to do runtime type checking.</p>
  
  <p><strong>So to boil it down, I just want to present a simple interface to the user with only the methods he needs, and none of the business he doesn't need. How can I do (or approximate) this?</strong> </p>
  
  <p>Thanks</p>