When you coding, it is not very often have to write duplicate code? : As shown, the two pieces of code is almost the same, but a little different, each written duplicates a lot of trouble, if you encounter such situations, you are how to solve?
[enter image description here][1]


[enter image description here][2]


  [1]: http://i.stack.imgur.com/j6VdG.png
  [2]: http://i.stack.imgur.com/fzQha.png