Avoid Code Duplication!  Principles & Patterns          Lars-Erik Kindblad           Senior Consultant          Blog: kind...
Agenda Why avoid code duplication? Principles and patterns:  Extract Method Principle  Inheritance Principle  Execute...
Why avoid code duplication? “The way you get programmer productivity is by eliminating the lines of  code you have to wri...
Extract Method Principle: Example                                    Duplicated Code
Extract Method Principle: Example              Extract the code to a new method
Extract Method Principle: Example              Refactored to call the new method
Inheritance Principle: Example                  Duplicated Code
Inheritance Principle: Example            Refactored to a common base class
Execute Around Method Pattern: Example                       Duplicated Code
Execute Around Method Pattern: Example         Refactored to a new execute around method
Execute Around Method Pattern: Example             Refactored to use the new method
Execute Around Method Pattern: Example                 Or:
About CapgeminiWith more than 120,000 people in 40 countries, Capgemini is oneof the worlds foremost providers of consulti...
Avoid code duplication! Principles & Patterns
Upcoming SlideShare
Loading in …5
×

Avoid code duplication! Principles & Patterns

3,899 views

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
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
3,899
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
48
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Avoid code duplication! Principles & Patterns

  1. 1. Avoid Code Duplication! Principles & Patterns Lars-Erik Kindblad Senior Consultant Blog: kindblad.com
  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 www.capgemini.com The information contained in this presentation is proprietary. © 2012 Capgemini. All rights reserved.

×