Skip to content

Instantly share code, notes, and snippets.

@buiquangduc
Created October 9, 2017 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buiquangduc/2bbcd87fd29b15581b72cbec77ce0822 to your computer and use it in GitHub Desktop.
Save buiquangduc/2bbcd87fd29b15581b72cbec77ce0822 to your computer and use it in GitHub Desktop.
Refactor routine from sequential cohesion to functional cohesion
<?php
//Example of routine with sequential cohesion
function randomRoutineName($birthDate) {
// Calculate the age from the birth date
$currentAge = // Stuff to get current age from birth date
// Calculate the retirement time from the current age
$retirementTime = // Stuff to get retirement time from current age
}
// Refactor to make this routine above functionally cohesive by separate to two routines
function getAge($birthDate) {
// Stuff to get current age from birth date
}
function getRetirementTime($currentAge) {
// Stuff to get retirement time from current age
}
// Now both getAge and getRetirementTime routines have functional cohesion. Other routines could call either routine or both routine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment