title: Apply design pattern to reduce code duplication
body: <p>I have the following class that all other Activities extend from.  Here is some pseudocode:</p>
  
  <pre><code>public class CommonActivity extends Activity
  {
      //class member variables
  
      protected void setupInterface(String activityName)
      {
          //a bunch of setup code here
          Button select = new Button;
          Button create = new Button;
          Button delete = new Button;
      }
      protected void resetScreen()
      {
          selectButton.highlight();
          createButton.unhighlight();
          deleteButton.unhighlight();
      }
  }
  </code></pre>
  
  <p>I have five or six other classes that extend CommonActivity, and do something like the following:</p>
  
  <pre><code> public class SectionActivity extends CommonActivity
  {
      //class member variables
  
      protected void onCreate()
      {
          setupInterface("sectionActivity");
      }
  }
  </code></pre>
  
  <p>Now I have another Activity that extends from CommonActivity that is just a tiny bit different than the other activities.  I found myself writing the following code:</p>
  
  <pre><code>public class ExActivity extends CommonActivity
  {
      //class member variables
  
      protected void onCreate()
      {
          setupInterface2("sectionActivity");
      }
  }
  </code></pre>
  
  <p>and then adding the following methods to CommonActivity (in addition to what was already there):</p>
  
  <pre><code>protected void setupInterface2(string activityName)
      {
          //a bunch of setup code here
          Button select = new Button;
      }
  protected void resetScreen2()
      {
          selectButton.highlight();
      }
  </code></pre>
  
  <p>Now I find myself wondering the best way to eliminate the code duplication.  The comments in the code that say "a bunch of setup code" will never change among activities.  Should I be using some sort of design pattern here?  I toyed around with the idea of the Template Pattern, but then each of the five classes that use identical code for setupInterface would have that duplicate code in their respective classes while ExActivity would have its own implementation (hopefully that sentence even made sense).  I also thought about using the Strategy Pattern to encapsulate the unique code in setupInterface into their own class.  That seems reasonable to me, but I feel like there might be something more elegant.  I am even thinking at this point that I should just remove setupInterface2 and resetScreen2 from CommonActivity and simply override those methods in ExActivity.  That seems to be the simplest solution.  Any suggestions here would be great!</p>