Simple Design Applied    Spend more time creating         valuable codeAlistair McKinnell   Declan Whelan    @mckinnell   ...
Exercise
What is Simple Design? On an index card write up to three facts on an index card.    Be ready to share with          your ...
What is Simple Design? At your table gather the facts and count how many distinct    facts you came up with.
Introductions      ?
www.XProgramming.com
Exercise
Simple DesignAt your table order therules of simple design in      priority order.
Simple Design1. All tests must pass2. No code is duplicated3. Code is self-explanatory4. No superfluous parts exist
Simple Design1. All tests must pass2. No code is duplicated3. Code is self-explanatory4. No superfluous parts exist
Simple Design1. Passes its tests2. No code is duplicated3. Code is self-explanatory4. No superfluous parts exist
Simple Design1. Passes its tests2. Minimizes duplication3. Code is self-explanatory4. No superfluous parts exist
Simple Design1. Passes its tests2. Minimizes duplication3. Maximizes clarity4. No superfluous parts exist
Simple Design1. Passes its tests2. Minimizes duplication3. Maximizes clarity4. Has fewer elements
Simple Design1. Passes its tests (given TDD)2. Minimizes duplication3. Maximizes clarity4. Has fewer elements
Simple Design1. Passes its tests (given TDD)2. Minimizes duplication3. Maximizes clarity (fix names)4. Has fewer elements
Simple Design1. Passes its tests (given TDD)2. Minimizes duplication3. Maximizes clarity (fix names)4. Has fewer elements
That leaves me with two key elementsof simple design: remove duplication andfix bad names.When I remove duplication, I tend...
Simple Design• Remove duplication• Fix bad names
Simple Design       (for today)• Fix bad names    ❤    Choosing good names• Remove duplication    ❤    Commonality & Varia...
Exercise
Stroop Effect Green Red BluePurple Blue Purple Green Red BluePurple Blue Purple Blue Purple RedGreen Purple Green
Meaning:Colour:           black           yellow
Meaning:Colour:           blue           black
blackyellow
yellow red
redyellow
redyellow
blueblue
yellow blue
redred
bluered
yellowyellow
redyellow
redyellow
blueblack
yellowblack
blackblue
redblack
TheEnd
Exercise
CComBstr sVal                                 $.getJSON()                                        int result               ...
CComBstr sVal                                 $.getJSON()                                        int result               ...
Find a partner and each of you:1. select a name you thought was good2. explain why to your partner3. select a name you tho...
Choosing Good Names
Choosing Good Names    Use the telephone test for readability.    If someone could understand your    code when read aloud...
Telephone TestGoal Donor vs Gold Owner  Date genymdhms
Choosing Good Names    Splitters can be lumped more easily    than lumpers can be split.    It is easier to combine two co...
Splitting a Lumper Customer Address
Splitting a Lumper                  Customer AddressBilling Address     Mailing Address   Service Address
Lumping a SplitterBilling Address   Mailing Address   Service Address
Lumping a SplitterBilling Address   Mailing Address    Service Address                  Customer Address
Choosing Good Names    Pronounceable Names    Avoid Encodings
Pronounceable NamesUpdatePerfIndValueDecCountCmd
Pronounceable NamesUpdatePerfIndValueDecCountCmdDecrementAggregateCommand
Pronounceable NamesDate genymdhms
Pronounceable NamesDate genymdhmsDate generatedTimestamp
Avoid EncodingsLPSTR lpCmdLineLPSTR commandLinem_namename
Choosing Good Names    Intention-Revealing Name    Role-Suggesting Name
Intention-Revealing NameapplyMeasureConstraintTo    EnableSortingByMeasure()
Intention-Revealing NameapplyMeasureConstraintTo    EnableSortingByMeasure()applyMeasureConstraint()
Role-Suggesting Nameint resultIndexCardPageLayout sut
Choosing Good Names    Ubiquitous Language
Ubiquitous LanguageCComBstr sVal
Ubiquitous LanguageCComBstr sValCComBstr calibrationToolName
Ubiquitous LanguageRx rx
Ubiquitous LanguageRx rxRx refillable
Ubiquitous LanguageapplyPhq9DateRangeConstraint()The PHQ-9 is the nine item depression scale ofthe Patient Health Question...
Pragmatic            Programmers                                 Agile in a Flash                                         ...
43            Really Meaningful Names               ® Are accurate               ® Are purposeful               ® Are pron...
Choosing Good Names                                                                                                     •L...
Choosing Good Namespublic List<int[]> getThem() {  List<int[]> list1 = new ArrayList<int[]>();    for (int[] x : theList) ...
Choosing Good Namespublic List<int[]> getThem() {  List<int[]> list1 = new ArrayList<int[]>();    for (int[] x : theList) ...
Choosing Good Namespublic List<int[]> getThem() {  List<int[]> list1 = new ArrayList<int[]>();    for (int[] x : theList) ...
Choosing Good Namespublic List<int[]> getThem() {  List<int[]> list1 = new ArrayList<int[]>();    for (int[] x : theList) ...
Choosing Good Namesint s = 0;for (int j=0; j<34; j++) {  s += (t[j]*4)/5;}const int EFFECTIVE_DAYS_PER_WEEK = 4;int realDa...
What’s In A Name?   Moonbeam    Zappa
All tests must pass       No code is duplicatedCode is self-explanatory   No superfluous parts exist
No code is duplicated
Exercise
How do you handle   duplicate code in your codebase?
Avoiding Duplicate Code     DRY: Don’t Repeat Yourself     Every piece of knowledge must have     a single, unambiguous, a...
Avoiding Duplicate Code     Once and Only Once     Data, structure, or logic should exist     in only one place in the sys...
Avoiding Duplicate Code     Test-Driven Development     1. Write new code only if an        automated test has failed.    ...
Avoiding Duplicate Code     Single Choice Principle     Whenever a software system must     support a set of alternatives,...
Avoiding Duplicate Code     Duplication may be the     root of all evil in software.
Commonality and Variability
Copy & Paste
function something() {}
function something() {}function something() {}
function something() {}function somethingElse() {}
function something() {}function somethingElse() {}
Duplicate CodeCopy & PasteEdit the Copy                ☞ Duplicate Code
Duplicate CodeAvoid duplication by expressing  commonality and variability           explicitly.
function something() {}function somethingElse() {}
Duplicate Code:Select Options
Can you spot the   commonality and variation?Can you spot the duplicate code?   How would you make thecommonality and vari...
public static List<SelectOption> createEndMonthList(Date expiryDate) {    int selectedMonth = getDateMonth(expiryDate);   ...
public static List<SelectOption> createEndMonthList(Date expiryDate) {    int selectedMonth = getDateMonth(expiryDate);   ...
public static List<SelectOption> createEndMonthList(Date expiryDate) {    int selectedMonth = getDateMonth(expiryDate);   ...
Select Options           SelectOptions                      SelectOptionsSourcecreate()                                  g...
Select Options           SelectOptions                       SelectOptionsSourcecreate()                                  ...
Select Options           SelectOptions               SelectOptionsSourcecreate()                           getFirst()     ...
Select Options           SelectOptions               SelectOptionsSourcecreate()                          getFirst()      ...
Duplicate Code:Compound Result Handler
Can you spot the   commonality and variation?Can you spot the duplicate code?   How would you make thecommonality and vari...
if ( ... ) {} else {}
Compound Result Handler    CompoundResultHandler                CompoundResultClassifier                                   ...
Compound Result Handler    CompoundResultHandler                CompoundResultClassifier                                   ...
Compound Result Handler      CompoundResultHandler                CompoundResultClassifier                                 ...
Compound Result Handler      CompoundResultHandler                CompoundResultClassifier                                 ...
Compound Result Handler        CompoundResultHandler                CompoundResultClassifier                               ...
Compound Result Handler        CompoundResultHandler                CompoundResultClassifier                               ...
Compound Result Handlerpublic static CompoundResultClassifier createCompoundResultClassifier(                             ...
Avoiding Duplicate Code
Commonality and Variability
Duplicate CodeCopy & PasteEdit the Copy                ☞ Duplicate Code
Duplicate CodeAvoid duplication by expressing  commonality and variability           explicitly.
All tests must pass       No code is duplicatedCode is self-explanatory   No superfluous parts exist
0   10   20   30   40   50   60   70   80
0   10   20   30   40   50   60   70   80
“The prime directive that wasunanimously agree upon by all present was that in the nexttens years Agile leaders mustDemand...
“Failure to do that meansyou are not an Agile leader.”                Jeff Sutherland
Personal Action Plan
Reading                                                                                        The Elements of Programming...
ReadingClean CodeA Handbook of Agile Software CraftsmanshipRobert C. MartinDomain Driven DesignTackling Complexity in the ...
ReadingThe Pragmatic Programmer: From Journeyman to MasterAndrew Hunt and Dave ThomasExtreme Programming Explained: Embrac...
ReadingDesign Patterns: Elements of ReusableObject-Oriented Software Erich Gamma,Richard Helm, Ralph Johnson, and John Vli...
Photo Creditshttp://www.flickr.com/photos/27558040@N00/4151899795/http://www.flickr.com/photos/popilop/331357312/http://www....
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Agile 2012 Simple Design Applied
Upcoming SlideShare
Loading in...5
×

Agile 2012 Simple Design Applied

1,797

Published on

Presentation at Agile 2012

Experience and research shows that developers spend as much as 70% of their time reading and understanding code. In this workshop you will learn how the rules of Simple Design help to reduce this percentage so you spend more time creating valuable code. This will be a highly collaborative workshop where you share your insights and learn from others. You’ll get to the heart of Simple Design by reviewing code - both beautiful and ugly. You’ll get to practice by improving the readability and understandability of real code. You’ll leave this workshop ready to apply Simple Design to improve your own code.

Published in: Self Improvement, Business

Agile 2012 Simple Design Applied

  1. 1. Simple Design Applied Spend more time creating valuable codeAlistair McKinnell Declan Whelan @mckinnell @dwhelan
  2. 2. Exercise
  3. 3. What is Simple Design? On an index card write up to three facts on an index card. Be ready to share with your table.
  4. 4. What is Simple Design? At your table gather the facts and count how many distinct facts you came up with.
  5. 5. Introductions ?
  6. 6. www.XProgramming.com
  7. 7. Exercise
  8. 8. Simple DesignAt your table order therules of simple design in priority order.
  9. 9. Simple Design1. All tests must pass2. No code is duplicated3. Code is self-explanatory4. No superfluous parts exist
  10. 10. Simple Design1. All tests must pass2. No code is duplicated3. Code is self-explanatory4. No superfluous parts exist
  11. 11. Simple Design1. Passes its tests2. No code is duplicated3. Code is self-explanatory4. No superfluous parts exist
  12. 12. Simple Design1. Passes its tests2. Minimizes duplication3. Code is self-explanatory4. No superfluous parts exist
  13. 13. Simple Design1. Passes its tests2. Minimizes duplication3. Maximizes clarity4. No superfluous parts exist
  14. 14. Simple Design1. Passes its tests2. Minimizes duplication3. Maximizes clarity4. Has fewer elements
  15. 15. Simple Design1. Passes its tests (given TDD)2. Minimizes duplication3. Maximizes clarity4. Has fewer elements
  16. 16. Simple Design1. Passes its tests (given TDD)2. Minimizes duplication3. Maximizes clarity (fix names)4. Has fewer elements
  17. 17. Simple Design1. Passes its tests (given TDD)2. Minimizes duplication3. Maximizes clarity (fix names)4. Has fewer elements
  18. 18. That leaves me with two key elementsof simple design: remove duplication andfix bad names.When I remove duplication, I tend to seean appropriate structure emerge, and whenI fix bad names, I tend to see responsibilitiesslide into appropriate parts of the design. J. B. Rainsberger
  19. 19. Simple Design• Remove duplication• Fix bad names
  20. 20. Simple Design (for today)• Fix bad names ❤ Choosing good names• Remove duplication ❤ Commonality & Variability
  21. 21. Exercise
  22. 22. Stroop Effect Green Red BluePurple Blue Purple Green Red BluePurple Blue Purple Blue Purple RedGreen Purple Green
  23. 23. Meaning:Colour: black yellow
  24. 24. Meaning:Colour: blue black
  25. 25. blackyellow
  26. 26. yellow red
  27. 27. redyellow
  28. 28. redyellow
  29. 29. blueblue
  30. 30. yellow blue
  31. 31. redred
  32. 32. bluered
  33. 33. yellowyellow
  34. 34. redyellow
  35. 35. redyellow
  36. 36. blueblack
  37. 37. yellowblack
  38. 38. blackblue
  39. 39. redblack
  40. 40. TheEnd
  41. 41. Exercise
  42. 42. CComBstr sVal $.getJSON() int result Rx rx applyMeasureConstraintToEnableSortingByMeasure() float hp applyPhq9DateRangeConstraint() public void run() Date genymdhms m_name Label label IShapeFactory Customer int i RollOverPerformanceIndicatorsToNextMonthTask CustomerManager LPSTR lpCmdLine int daysSinceModification boolean fNewPage UpdatePerfIndValueDecCountCmd DepressionSelfManagementCalculator Tutorial02PerfIndValueDecCountForMatchingIvpCmd PulseRenderer IndexCardPageLayout sut
  43. 43. CComBstr sVal $.getJSON() int result Rx rx applyMeasureConstraintToEnableSortingByMeasure() float hp applyPhq9DateRangeConstraint() public void run() Date genymdhms m_name Label label IShapeFactory Customer int i RollOverPerformanceIndicatorsToNextMonthTask CustomerManager LPSTR lpCmdLine int daysSinceModification boolean fNewPage UpdatePerfIndValueDecCountCmd DepressionSelfManagementCalculator Tutorial02PerfIndValueDecCountForMatchingIvpCmd PulseRenderer IndexCardPageLayout sut
  44. 44. Find a partner and each of you:1. select a name you thought was good2. explain why to your partner3. select a name you thought was bad4. explain why to your partner CComBstr sVal $.getJSON() int result Rx rx applyMeasureConstraintToEnableSortingByMeasure() float hp applyPhq9DateRangeConstraint() public void run() Date genymdhms m_name Label label IShapeFactory Customer int i RollOverPerformanceIndicatorsToNextMonthTask CustomerManager LPSTR lpCmdLine int daysSinceModification boolean fNewPage UpdatePerfIndValueDecCountCmd DepressionSelfManagementCalculator PerfIndValueDecCountForMatchingIvpCmd PulseRenderer IndexCardPageLayout sut
  45. 45. Choosing Good Names
  46. 46. Choosing Good Names Use the telephone test for readability. If someone could understand your code when read aloud over the telephone, its clear enough. If not, then it needs rewriting.
  47. 47. Telephone TestGoal Donor vs Gold Owner Date genymdhms
  48. 48. Choosing Good Names Splitters can be lumped more easily than lumpers can be split. It is easier to combine two concepts that it is to separate them.
  49. 49. Splitting a Lumper Customer Address
  50. 50. Splitting a Lumper Customer AddressBilling Address Mailing Address Service Address
  51. 51. Lumping a SplitterBilling Address Mailing Address Service Address
  52. 52. Lumping a SplitterBilling Address Mailing Address Service Address Customer Address
  53. 53. Choosing Good Names Pronounceable Names Avoid Encodings
  54. 54. Pronounceable NamesUpdatePerfIndValueDecCountCmd
  55. 55. Pronounceable NamesUpdatePerfIndValueDecCountCmdDecrementAggregateCommand
  56. 56. Pronounceable NamesDate genymdhms
  57. 57. Pronounceable NamesDate genymdhmsDate generatedTimestamp
  58. 58. Avoid EncodingsLPSTR lpCmdLineLPSTR commandLinem_namename
  59. 59. Choosing Good Names Intention-Revealing Name Role-Suggesting Name
  60. 60. Intention-Revealing NameapplyMeasureConstraintTo EnableSortingByMeasure()
  61. 61. Intention-Revealing NameapplyMeasureConstraintTo EnableSortingByMeasure()applyMeasureConstraint()
  62. 62. Role-Suggesting Nameint resultIndexCardPageLayout sut
  63. 63. Choosing Good Names Ubiquitous Language
  64. 64. Ubiquitous LanguageCComBstr sVal
  65. 65. Ubiquitous LanguageCComBstr sValCComBstr calibrationToolName
  66. 66. Ubiquitous LanguageRx rx
  67. 67. Ubiquitous LanguageRx rxRx refillable
  68. 68. Ubiquitous LanguageapplyPhq9DateRangeConstraint()The PHQ-9 is the nine item depression scale ofthe Patient Health Questionnaire.The PHQ-9 is a powerful tool for assisting primarycare clinicians in diagnosing depression as well asselecting and monitoring treatment.
  69. 69. Pragmatic Programmers Agile in a Flash Speed-Learning Agile Software Development Agile Cards for Agile Teams Jeff Langr and Tim Ottinger edited by Susannah PfalzerPrepared exclusively for Alistair McKinnell Copyright ©2011 Pragmatic Programmers
  70. 70. 43 Really Meaningful Names ® Are accurate ® Are purposeful ® Are pronounceable ® Begin well ® Are simple ® Depend on context ® Match name length to scopePrepared exclusively for Alistair McKinnell Copyright ©2011 Pragmatic Programmers
  71. 71. Choosing Good Names •Locate one NamingGuidelinesSystemofNames S1# # Name#pass#the#“telephone”#test. S2# # There#is#a#clean#name#for#each#concept.#Remember:#later#on#it’s#easier#to#lump# guideline that if things#together#than#to#split#them#apart. S3# # Name#is#from#the#problem#or#solu?on#domain#and#support#ubiquitous#language#for# the#teamGeneral applied would have G1## Name#is#pronounceable. G2## Name#avoids#encodings#and#member#prefixes. G3## Name#suggest#why#it#exists. G4## Name#suggest#how#it#should#be#used. the biggest impact G5## Name#suggest#what#it#does. G6## Name#is#easily#searchable#in#the#code#base.Classes C1# If#this#is#an#important#base#class#its#class#name#should#be#a#simple#single#word. C2# C3# If#this#is#a#subclass#its#class#name#suggests#how#it#differs#from#its#superclass. The#class#name#is#a#noun#or#a#noun#phrase. on your code •Find a partnerMethods M1# The#method#name#suggests#why#it#would#be#called. M2# The#method#is#name#a#verb#or#a#verb#phrase.Variables/Fields/Arguments •Discuss V1# Its#name#indicate#the#role#its#playing. V2# The#length#of#the#name#reflect#its#scope.Alistair McKinnell @amckinnell Declan Whelan @dwhelanNaming Guidelines v1.0 August 2012 ! 1/1
  72. 72. Choosing Good Namespublic List<int[]> getThem() { List<int[]> list1 = new ArrayList<int[]>(); for (int[] x : theList) if (x[0] == 4) list1.add(x); return list1;}Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
  73. 73. Choosing Good Namespublic List<int[]> getThem() { List<int[]> list1 = new ArrayList<int[]>(); for (int[] x : theList) if (x[0] == 4) list1.add(x); return list1;}public List<int[]> getFlaggedCells() { List<int[]> flaggedCells = new ArrayList<int[]>(); for (int[] cell : gameBoard) if (cell[STATUS_VALUE] == FLAGGED) flaggedCells.add(cell); return flaggedCells;}Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
  74. 74. Choosing Good Namespublic List<int[]> getThem() { List<int[]> list1 = new ArrayList<int[]>(); for (int[] x : theList) if (x[0] == 4) list1.add(x); return list1;}public List<Cell> getFlaggedCells() { List<Cell> flaggedCells = new ArrayList<Cell>(); for (Cell cell : gameBoard) if (cell.isFlagged()) flaggedCells.add(cell); return flaggedCells;}Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
  75. 75. Choosing Good Namespublic List<int[]> getThem() { List<int[]> list1 = new ArrayList<int[]>(); for (int[] x : theList) if (x[0] == 4) list1.add(x); return list1;}public List<Cell> getFlaggedCells() { List<Cell> result = new ArrayList<Cell>(); for (Cell cell : gameBoard) if (cell.isFlagged()) result.add(cell); return result;}Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, pages 18-19
  76. 76. Choosing Good Namesint s = 0;for (int j=0; j<34; j++) { s += (t[j]*4)/5;}const int EFFECTIVE_DAYS_PER_WEEK = 4;int realDaysPerIdealDay = 4;const int WORKING_DAYS_PER_WEEK = 5;const int WORK_DAYS_PER_WEEK = 5;int sum = 0;int effectiveTotalEstimate = 0;for (int j=0; j < NUMBER_OF_TASKS; j++) {for (int j=0; j < NUMBER_OF_TASKS; j++) {realDaysPerIdealDay; int realTaskDays = taskEstimate[j] * int effectiveTaskEstimate = int realTaskWeeks = (realdays / WORK_DAYS_PER_WEEK); taskEstimate[j] * EFFECTIVE_DAYS_PER_WEEK / WORKING_DAYS_PER_WEEK; sum += realTaskWeeks; effectiveTotalEstimate += effectiveTaskEstimate;}} Source: Clean Code: A Handbook of Agile Software Craftsmanship, Robert C. Martin, page 23
  77. 77. What’s In A Name? Moonbeam Zappa
  78. 78. All tests must pass No code is duplicatedCode is self-explanatory No superfluous parts exist
  79. 79. No code is duplicated
  80. 80. Exercise
  81. 81. How do you handle duplicate code in your codebase?
  82. 82. Avoiding Duplicate Code DRY: Don’t Repeat Yourself Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
  83. 83. Avoiding Duplicate Code Once and Only Once Data, structure, or logic should exist in only one place in the system.
  84. 84. Avoiding Duplicate Code Test-Driven Development 1. Write new code only if an automated test has failed. 2. Eliminate duplication.
  85. 85. Avoiding Duplicate Code Single Choice Principle Whenever a software system must support a set of alternatives, one and only one module in the system should know their exhaustive list.
  86. 86. Avoiding Duplicate Code Duplication may be the root of all evil in software.
  87. 87. Commonality and Variability
  88. 88. Copy & Paste
  89. 89. function something() {}
  90. 90. function something() {}function something() {}
  91. 91. function something() {}function somethingElse() {}
  92. 92. function something() {}function somethingElse() {}
  93. 93. Duplicate CodeCopy & PasteEdit the Copy ☞ Duplicate Code
  94. 94. Duplicate CodeAvoid duplication by expressing commonality and variability explicitly.
  95. 95. function something() {}function somethingElse() {}
  96. 96. Duplicate Code:Select Options
  97. 97. Can you spot the commonality and variation?Can you spot the duplicate code? How would you make thecommonality and variation explicit?
  98. 98. public static List<SelectOption> createEndMonthList(Date expiryDate) { int selectedMonth = getDateMonth(expiryDate); SelectOptionsSource months = new SelectOptionsSource(1, 12, selectedMonth); SelectOptions monthOptions = new SelectOptions(months); return monthOptions.create();}public static List<SelectOption> createEndDaysList() { int selectedDay = getDateDay(getCurrentDatePlus14Days()); SelectOptionsSource days = new SelectOptionsSource(1, 31, selectedDay); SelectOptions dayOptions = new SelectOptions(days); return dayOptions.create();}public static List<SelectOption> createEndYearList() { int selectedYear = getDateYear(getCurrentDatePlus14Days()); SelectOptionsSource years = new SelectOptionsSource(1985, 1985 + 30, selectedYear); SelectOptions yearOptions = new SelectOptions(years); return yearOptions.create();}
  99. 99. public static List<SelectOption> createEndMonthList(Date expiryDate) { int selectedMonth = getDateMonth(expiryDate); SelectOptionsSource months = new SelectOptionsSource(1, 12, selectedMonth); SelectOptions monthOptions = new SelectOptions(months); return monthOptions.create();}public static List<SelectOption> createEndDaysList() { int selectedDay = getDateDay(getCurrentDatePlus14Days()); SelectOptionsSource days = new SelectOptionsSource(1, 31, selectedDay); SelectOptions dayOptions = new SelectOptions(days); return dayOptions.create();}public static List<SelectOption> createEndYearList() { int selectedYear = getDateYear(getCurrentDatePlus14Days()); SelectOptionsSource years = new SelectOptionsSource(1985, 1985 + 30, selectedYear); SelectOptions yearOptions = new SelectOptions(years); return yearOptions.create();}
  100. 100. public static List<SelectOption> createEndMonthList(Date expiryDate) { int selectedMonth = getDateMonth(expiryDate); SelectOptionsSource months = new SelectOptionsSource(1, 12, selectedMonth); SelectOptions monthOptions = new SelectOptions(months); return monthOptions.create();}public static List<SelectOption> createEndDaysList() { int selectedDay = getDateDay(getCurrentDatePlus14Days()); SelectOptionsSource days = new SelectOptionsSource(1, 31, selectedDay); SelectOptions dayOptions = new SelectOptions(days); return dayOptions.create();}public static List<SelectOption> createEndYearList() { int selectedYear = getDateYear(getCurrentDatePlus14Days()); SelectOptionsSource years = new SelectOptionsSource(1985, 1985 + 30, selectedYear); SelectOptions yearOptions = new SelectOptions(years); return yearOptions.create();}
  101. 101. Select Options SelectOptions SelectOptionsSourcecreate() getFirst() getLast() isSelected() Commonality Variability Resolution Encapsulate Behaviour Collaborator Collection
  102. 102. Select Options SelectOptions SelectOptionsSourcecreate() getFirst() getLast() isSelected() Commonality Variability Resolution Data Structure Value of State Simple Java Type
  103. 103. Select Options SelectOptions SelectOptionsSourcecreate() getFirst() getLast() isSelected() Encapsulate Collection
  104. 104. Select Options SelectOptions SelectOptionsSourcecreate() getFirst() getLast() isSelected() Parameter Object
  105. 105. Duplicate Code:Compound Result Handler
  106. 106. Can you spot the commonality and variation?Can you spot the duplicate code? How would you make thecommonality and variation explicit?
  107. 107. if ( ... ) {} else {}
  108. 108. Compound Result Handler CompoundResultHandler CompoundResultClassifier isNegative() isPositive() AbstractCompoundResultClassifier toNumber() QueensCompoundResultClassifier StandardCompoundResultClassifier isNegative() isNegative() isPositive() isPositive()
  109. 109. Compound Result Handler CompoundResultHandler CompoundResultClassifier isNegative() isPositive() AbstractCompoundResultClassifier toNumber() QueensCompoundResultClassifier StandardCompoundResultClassifier isNegative() isNegative() isPositive() isPositive()
  110. 110. Compound Result Handler CompoundResultHandler CompoundResultClassifier isNegative() isPositive() AbstractCompoundResultClassifier toNumber() QueensCompoundResultClassifier StandardCompoundResultClassifier isNegative() isNegative() isPositive() isPositive() Commonality Variability Resolution Inheritance Behaviour Implementation (Object-Oriented)
  111. 111. Compound Result Handler CompoundResultHandler CompoundResultClassifier isNegative() isPositive() AbstractCompoundResultClassifier toNumber() QueensCompoundResultClassifier StandardCompoundResultClassifier isNegative() isNegative() isPositive() isPositive() Commonality Variability Resolution Inheritance Behaviour Implementation (Object-Oriented)
  112. 112. Compound Result Handler CompoundResultHandler CompoundResultClassifier isNegative() isPositive() AbstractCompoundResultClassifier toNumber() QueensCompoundResultClassifier StandardCompoundResultClassifier isNegative() isNegative() isPositive() isPositive() Commonality Variability Resolution Implementation None Base Class
  113. 113. Compound Result Handler CompoundResultHandler CompoundResultClassifier isNegative() isPositive() AbstractCompoundResultClassifier toNumber() QueensCompoundResultClassifier StandardCompoundResultClassifier isNegative() isNegative() isPositive() isPositive() Commonality Variability Resolution Implementation None Base Class
  114. 114. Compound Result Handlerpublic static CompoundResultClassifier createCompoundResultClassifier( Patient sourcePatient) { return isRegisteredAtQueens(sourcePatient) ? QUEENS : STANDARD;}private static boolean isRegisteredAtQueens(Patient sourcePatient) { return sourcePatient.getDataWarehouse().equals(DataWarehouseTag.QHN);} Factory
  115. 115. Avoiding Duplicate Code
  116. 116. Commonality and Variability
  117. 117. Duplicate CodeCopy & PasteEdit the Copy ☞ Duplicate Code
  118. 118. Duplicate CodeAvoid duplication by expressing commonality and variability explicitly.
  119. 119. All tests must pass No code is duplicatedCode is self-explanatory No superfluous parts exist
  120. 120. 0 10 20 30 40 50 60 70 80
  121. 121. 0 10 20 30 40 50 60 70 80
  122. 122. “The prime directive that wasunanimously agree upon by all present was that in the nexttens years Agile leaders mustDemand Technical Excellence.” Jeff Sutherland
  123. 123. “Failure to do that meansyou are not an Agile leader.” Jeff Sutherland
  124. 124. Personal Action Plan
  125. 125. Reading The Elements of Programming Style Kernighan and Plauger Prefactoring Extreme Abstraction Extreme Separation Extreme Readability Ken Pugh Pragmatic Programmers Agile in a Flash Speed-Learning Agile Software Development Agile in a Flash Agile Cards for Agile Teams Speed-Learning Agile Development Jeff Langr and Tim Ottinger edited by Susannah Pfalzer Jeff Langr and Tim OttingerPrepared exclusively for Alistair McKinnell
  126. 126. ReadingClean CodeA Handbook of Agile Software CraftsmanshipRobert C. MartinDomain Driven DesignTackling Complexity in the Heart of SoftwareEric EvansImplementation PatternsKent Beck
  127. 127. ReadingThe Pragmatic Programmer: From Journeyman to MasterAndrew Hunt and Dave ThomasExtreme Programming Explained: Embrace ChangeKent Beck and Cynthia AndresTest Driven Development: By ExampleKent BeckObject-Oriented Software ConstructionBertrand Meyer
  128. 128. ReadingDesign Patterns: Elements of ReusableObject-Oriented Software Erich Gamma,Richard Helm, Ralph Johnson, and John VlissidesMulti-Paradigm Design for C++James O. CoplienLean Architecture: for Agile Software DevelopmentJames O. Coplien and Gertrud Bjørnvig
  129. 129. Photo Creditshttp://www.flickr.com/photos/27558040@N00/4151899795/http://www.flickr.com/photos/popilop/331357312/http://www.flickr.com/photos/arlette/3260468/http://www.flickr.com/photos/36829973@N04/3546657245/http://www.flickr.com/photos/40838054@N00/7261734660/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×