title: connecting two classes with each other
body: <p>So, I want to create a correlation between two classes, from what I have read in some design patterns, it convenient, to use an interface, (in Android Studio it is used to bind a fragment with a activity).</p>
  
  <p>Look at this code:</p>
  
  <p>First, we have class A:</p>
  
  <pre><code>public class A {
  
  public static void main(String[] args) {
      B b = new B();
      b.foo();
  }
  }
  </code></pre>
  
  <p>Then, we have class B:</p>
  
  <pre><code>class B {
  private int i;
  
  interface Drawable {
      void show(int i);
  }
  
  public B() {
      this.i = 5393;
      drawable = new C();
  }
  private Drawable drawable;
  
  public void foo() {
      drawable.show(this.i);
  }
  }
  </code></pre>
  
  <p>And at the end class C:</p>
  
  <pre><code>class C implements B.Drawable {
  
  @Override
  public void show(int i) {
      System.out.println("I'm showing this method, and i = " + i);
  }
  }
  </code></pre>
  
  <p>What I'm wrapping my head around is this line:</p>
  
  <pre><code>drawable = new C();
  </code></pre>
  
  <p>Can someone explain me how are we assigning new object from class C, to a interface, I know it is because class C implements that interface, yet, it is hard for me to get it all. The general view of this operation is pretty harsh for me to overcome.</p>
  
  <p>In Android we are assigning that interface to a Activity, (the recent patch changed it into a context, which is a instance of a Activity).</p>