Skip to content

Instantly share code, notes, and snippets.

@buiquangduc
Created October 10, 2017 05:43
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/5e0800d7f81f54b450c8f24838d5beea to your computer and use it in GitHub Desktop.
Save buiquangduc/5e0800d7f81f54b450c8f24838d5beea to your computer and use it in GitHub Desktop.
Improve routine with logical cohesion
<?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