title: Java: Object Oriented Design; LinkedList and Stack
body: <p>I am writing a BFS and DFS in Java.  What I was hoping to do was create one class like this:</p>
  
  <pre><code>/** Preforms BFS and DFS on ...
  */
  public class Search{
  
  
    private XXX toSearch;
    // where XXX is an interface of Stack and LinkedList that has
    // remove() and add() methods.  
  
    public Search(boolean isBFS){
      if(isBFS)
        toSearch = new LinkedList();
      else
        toSearch = new Stack();
    }
  
    public void preformSearch(){
      while(toSearch.size() &gt; 0){
        preformSearchOn(toSearch.remove());  // &lt;----- KEY LINE
      }
    }
  
    private void preformSearchOn(...){...}
  
  }
  </code></pre>
  
  <p>This class can perform BFS and DFS depending on how it is initialized.  What is XXX?  I don't think that it exists.  </p>
  
  <p>I thought that the entire point of object oriented programing is being able to do cool stuff like this.  </p>
  
  <p>What is the cleanest way to handle this?  </p>