title: How to implement Command Pattern for CRUD operations
body: <p>I have a UI with Create , Update , Delete and Select Operations , so for this i thought to design it using Command Pattern</p>
  
  <p><strong>MyServlet</strong> </p>
  
  <pre><code>public void doGet(HttpServletRequest req,HttpServletResponse res)
       throws ServletException,IOException
      {
  
  InsertCommand insertCommnd = new InsertCommand();
  DeleteCommand deleteCommnd = new DeleteCommand();
  </code></pre>
  
  <p>// Create the DTO Employee with request parameters and pass it to invoker</p>
  
  <pre><code>if(req.getParameter("action").equals("insert"))
  
    Invoker invoker = new Invoker();
  
   invoker.setCommand(insertCommnd );
   invoker.pressButton(emp);
  
  
      }
  </code></pre>
  
  <p><strong>//*<em>Invoker</em>*</strong></p>
  
  <pre><code>public class Invoker
  {
      private Command command;
  
      public void setCommand(Command command)
      {
          this.command = command;
      }
  
  
      public void pressButton(Employee emp)
      {
          command.execute(emp);
      }
  
  }
  </code></pre>
  
  <p>//<strong>Command</strong>.java</p>
  
  <pre><code>public interface Command
  {
  public void execute();
  }
  </code></pre>
  
  <p><strong>DeleteCommand</strong>.java</p>
  
  <pre><code>public DeleteCommand implements Command
  {   
  
  Employee emp;
  
  public DeleteCommand(Employee emp)
  {
  
  this.emp = emp;
  }
  
  public void execute()
  {
  // SQL Query to delete Records
  }
  
  }
  </code></pre>
  
  <p><strong>InsertCommand.java</strong></p>
  
  <pre><code> public InsertCommand implements Command
      {
       Employee emp ;
      public InsertCommand(Employee emp)
      {
  
      this.emp = emp;
      }
  
      public void execute()
      {
      // SQL Query to insert Records
      }
  
      }
  </code></pre>
  
  <p>Similarly there is a Update Records command</p>
  
  <p>My question is , how can i handle this in case of Select Operations as it returns a ArrayList from Database ?</p>
  
  <p>Also please share your ideas on this design ,as i am new to Designing Software .</p>