title: Using strategy design pattern with an abstract parameter
body: <p>I am currently working on a pretty simple project to improve my SOLID and Design Patterns Knowledge.
  The idea was to create a "Smart Lock" for a door that can recognize a person by different parameters such as fingerprints, facial recognition, etc.</p>
  
  <p>I immediately saw the potential in using the Strategy Design Pattern, and therefore I created a <strong>Lock</strong> interface and a <strong>Key</strong> abstract class:</p>
  
  <pre><code>public interface Lock {
      boolean unlock(Key key);
  }
  
  public abstract class Key {
      private String id;
  
      public String getId(){
          return (this.id);
      }
  }
  </code></pre>
  
  <p>I created two classes that will extend <strong>Key</strong> - <strong>FacePhoto</strong> and <strong>FingerPrint</strong>:</p>
  
  <pre><code>public class FacePhoto extends Key {
  }
  
  public class FingerPrint extends Key {
  }
  </code></pre>
  
  <p>Then I created classes that implement <strong>Lock</strong> such as <strong>FingerPrintRecognizer</strong> and <strong>FacialRecognizer</strong>:</p>
  
  <pre><code>public class FacialRecognizer implements Lock {
      @Override
      public boolean unlock(Key key) throws Exception {
          if(key instanceof FacePhoto){
              //check validity
              return true;
          }
          else {
              throw new Exception("This key does not fit this lock");
          }
      }
  }
  
  public class FingerPrintRecognizer implements Lock {
      @Override
      public boolean unlock(Key key) throws Exception {
          if(key instanceof FingerPrint){
              //check validity
              return true;
          }
          else {
              throw new Exception("This key does not fit this lock");
          }
      }
  }
  </code></pre>
  
  <p>I couldn't really find a better way to handle cases in which users of the <strong>Lock</strong> interface will try to open Locks with keys that don't fit.
  Also, I had trouble with the "instanceof" if statement because it appears in every class that implements <strong>Lock</strong>.</p>
  
  <p>Is Strategy a good practice in this case? if not, what would be a fine alternative (a different Design Pattern perhaps).</p>