Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Avoid code duplication! Principles & Patterns


Published on

A presentation I gave for the Capgemini Microsoft Group on principles and patterns to use in order to avoid code duplication.

Published in: Technology
  • Be the first to like this

Avoid code duplication! Principles & Patterns

  1. 1. Avoid Code Duplication! Principles & Patterns Lars-Erik Kindblad Senior Consultant Blog:
  2. 2. Agenda Why avoid code duplication? Principles and patterns:  Extract Method Principle  Inheritance Principle  Execute Around Method Pattern
  3. 3. Why avoid code duplication? “The way you get programmer productivity is by eliminating the lines of code you have to write” – Steve Jobs How? Stop duplicating and repeating code! Less Code to Write = Less Code to Maintain = More features delivered = More productive We normalize databases – should also normalize our code DRY – Don’t repeat yourself – Single Source of Truth
  4. 4. Extract Method Principle: Example Duplicated Code
  5. 5. Extract Method Principle: Example Extract the code to a new method
  6. 6. Extract Method Principle: Example Refactored to call the new method
  7. 7. Inheritance Principle: Example Duplicated Code
  8. 8. Inheritance Principle: Example Refactored to a common base class
  9. 9. Execute Around Method Pattern: Example Duplicated Code
  10. 10. Execute Around Method Pattern: Example Refactored to a new execute around method
  11. 11. Execute Around Method Pattern: Example Refactored to use the new method
  12. 12. Execute Around Method Pattern: Example Or:
  13. 13. About CapgeminiWith more than 120,000 people in 40 countries, Capgemini is oneof the worlds foremost providers of consulting, technology andoutsourcing services. The Group reported 2011 global revenuesof EUR 9.7 billion.Together with its clients, Capgemini creates and deliversbusiness and technology solutions that fit their needs and drivethe results they want. A deeply multicultural organization,Capgemini has developed its own way of working, theCollaborative Business ExperienceTM, and draws on Rightshore ®,its worldwide delivery model.Rightshore® is a trademark belonging to Capgemini The information contained in this presentation is proprietary. © 2012 Capgemini. All rights reserved.