Created
October 10, 2017 05:43
-
-
Save buiquangduc/5e0800d7f81f54b450c8f24838d5beea to your computer and use it in GitHub Desktop.
Improve routine with logical cohesion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example of routine with logical cohesion | |
function update($name, $input) { | |
switch($name) { | |
case 'person': | |
// Stuff to update person with input data | |
break; | |
case 'car': | |
// Stuff to update car with input data | |
break; | |
case 'building': | |
// Stuff to update building with input data | |
break; | |
} | |
} | |
// You can separate this routine to three routines like this | |
// If the operations above use some of the same code or share data, the code should be moved into a lower-level routine | |
updatePerson($input); | |
updateCar($input); | |
updateBuilding($input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment