title: How to implement an interface, whose two instances can depend on each other, in a skeletal implementation, i.e. class, without downcast?
body: <p>Given a <code>Person</code> interface:</p>
  
  <pre><code>public interface Person {
      Person getSpouse();
      void marry(Person spouse);
  }
  </code></pre>
  
  <p>I made a <em>skeletal implementation</em>:</p>
  
  <pre><code>public abstract class AbstractPerson implements Person {
      private Person spouse;
      @Override
      public Person getSpouse() {
          return spouse;
      }
      @Override
      public void marry(Person spouse) {
          this.spouse = spouse;
          ((MarriedPerson) spouse).setSpouse(this);//forced to downcast
      }
      protected void setSpouse(Person spouse) {
          this.spouse = spouse;
      }
  }
  </code></pre>
  
  <p>The drawback of calling the <code>marry(Person spouse)</code> with the <em>skeletal implementation</em> is the <em>argument</em> <code>spouse</code> has to be an instance of <code>AbstractPerson</code>. However, if the <code>spouse.marry(this)</code> is called inside the <code>marry()</code>, it will loop endlessly and wind up with <em>stack overflow error</em></p>
  
  <p><strong>Question: is it possible to implement the marry(Person spouse) without downcast? how?</strong></p>