title: Passing Files as Parameters
body: <p>I have created an example to introduce my question.</p>
  
  <pre><code>public class Algorithm
  {
      // This is the best, but circumstances prevent me from doing this.
      /*public static void computeSomething(Data data)
      {
          // Compute some stuff
      }*/
  
      public static void computeSomething(DataFileReader reader) throws IOException
      {
          // Compute some stuff.
      }
  
      public static void computeSomething(File file) throws IOException, DataFormatException
      {
          DataFileReader = DataFileReaderFactory.newDataFileReader(file);
  
          // Compute some stuff.
      }
  }
  
  public class DataFileReaderFactory
  {
      private enum FileExtension { XML, UNSUPPORTED_EXTENSION }
  
      private static final String XMLExtension = ".xml";
  
      public static DataFileReader newDataFileReader(File file) throws DataFormatException
      {
          switch(computeFileExtension(file))
          {
              case XML :  return new XMLFileReader(file);
  
              default :   throw new DataFormatException();
          }
      }
  
      private static FileExtension computeFileExtension(File file)
      {
          if(file.getName().endsWith(XMLExtension))
              return FileExtension.XML;
          else
              return FileExtension.UNSUPPORTED_EXTENSION;
      }
  }
  </code></pre>
  
  <p>So, I would like to know if I should define my interface to take <em>Files</em>, or my own file readers, which ensure that the data is in a valid format.  Obviously, I would like to be able to take the data itself as a <em>Data</em> object, but I am limited in this regard.  The reason has to do with the data being very large and me having to serialize it for multiple objects.  In this case, it is more practical to send a path to the data rather than the data itself.</p>
  
  <p>Anyhow, in regards to the question, I am leaning toward the method which takes an instance of Java's <em>File,</em> as it seems more general, but I want hear your advice.  Thanks!</p>