avoid code duplication! principles & patterns

Post on 19-Jun-2015

2.158 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Avoid Code Duplication! Principles & Patterns

Lars-Erik KindbladSenior Consultant

Blog: kindblad.com

Agenda

Why avoid code duplication?Principles and patterns:

Extract Method Principle Inheritance Principle Execute Around Method Pattern

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 codeDRY – Don’t repeat yourself – Single Source of Truth

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:

The information contained in this presentation is proprietary.© 2012 Capgemini. All rights reserved.

www.capgemini.com

About Capgemini

With more than 120,000 people in 40 countries, Capgemini is one of the world's foremost providers of consulting, technology and outsourcing services. The Group reported 2011 global revenues of EUR 9.7 billion.Together with its clients, Capgemini creates and delivers business and technology solutions that fit their needs and drive the results they want. A deeply multicultural organization, Capgemini has developed its own way of working, the Collaborative Business ExperienceTM, and draws on Rightshore ®, its worldwide delivery model.

Rightshore® is a trademark belonging to Capgemini

top related