title: What pattern to use with a Strategy Pattern to avoid duplicate code inside Concrete Strategies?
body: <p>I'm relatively new to design patterns and in the following example I am using what I believe is a Strategy Pattern. However, I am repeating myself inside <strong>some, not all,</strong> concrete strategies and wondering is there a way to avoid this? Notice how ACommand and CCommand have the same code before doing something unique.</p>
  
  <pre><code>public interface Command 
  {
      public boolean execute(CommandSender sender, String[] args);
      public String getName();
      //...
  }
  
  public abstract class PlayerCommand implements Command 
  {
      protected BukkitPlugin plugin = BukkitPlugin.getInstance();
  
      private String name;
      //...
  
      public PlayerCommand(String name) 
      {
          this.name = name;
      }
  
      public String getName() 
      {
          return this.name;
      }
  
      //...
  }
  </code></pre>
  
  <p><strong>ACommand</strong></p>
  
  <pre><code>    public class ACommand extends PlayerCommand
      {
          public ACommand()
          {
              super("A");
          }
  
          public boolean execute(CommandSender sender, String[] args)
          {
              Player player = (Player) sender;
              PlayerInventory inventory = player.getInventory();
              ItemStack itemInHand = inventory.getItemInHand();
  
              if(itemInHand.getType() != Material.COMPASS)
              {
                  sender.sendMessage("You must be holding a phone to use this command");
                  return true;
              }
  
              int id = itemInHand.getDurability();
  
              MobilePhoneManager phoneManager = plugin.getMobilePhoneManager();       
              boolean isMobilePhone = phoneManager.isMobilePhone(id);
  
              if(!isMobilePhone)
              {
                  sender.sendMessage("You must be holding a mobile phone to use this command");
                  return true;
              }
  
              //DO SOMETHING UNIQUE HERE
          }
  }
  </code></pre>
  
  <p><strong>BCommand</strong></p>
  
  <pre><code>public class BCommand extends PlayerCommand
          {
              public BCommand()
              {
                  super("B");
              }
  
              public boolean execute(CommandSender sender, String[] args)
              {
                  //SOMETHING ELSE
              }
      }
  </code></pre>
  
  <p><strong>CCommand</strong></p>
  
  <pre><code>    public class CCommand extends PlayerCommand
      {
          public CCommand()
          {
              super("C");
          }
  
          public boolean execute(CommandSender sender, String[] args)
          {
              Player player = (Player) sender;
              PlayerInventory inventory = player.getInventory();
              ItemStack itemInHand = inventory.getItemInHand();
  
              if(itemInHand.getType() != Material.COMPASS)
              {
                  sender.sendMessage("You must be holding a phone to use this command");
                  return true;
              }
  
              int id = itemInHand.getDurability();
  
              MobilePhoneManager phoneManager = plugin.getMobilePhoneManager();       
              boolean isMobilePhone = phoneManager.isMobilePhone(id);
  
              if(!isMobilePhone)
              {
                  sender.sendMessage("You must be holding a mobile phone to use this command");
                  return true;
              }
  
              //DO SOMETHING UNIQUE HERE
          }
  }
  </code></pre>