Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active December 24, 2023 15:16
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 mcsee/bde14771106be4ffad1389a16f23c5c8 to your computer and use it in GitHub Desktop.
Save mcsee/bde14771106be4ffad1389a16f23c5c8 to your computer and use it in GitHub Desktop.
<?
Interface SocialInteraction {
public function propagate($aVirus);
}
final class SocialDistancing implements SocialInteraction {
public function propagate($aVirus) {
// Do nothing !!!!
}
}
final class PersonToPersonInteraction implements SocialInteraction {
public function propagate($aVirus) {
if ($this->somePerson->isInfectedWith($aVirus)
&& $aVirus->infectionProbability() > random()) {
$this->anotherPerson->getInfectedWith($aVirus);
}
}
}
final class City {
public function interactionBetween($aPerson, $anotherPerson) {
return new SocialDistancing();
// The cities are smart enough to implement
// social distancing to model Person to Person interactions
}
}
$covid19 = new Virus();
$janeDoe = new Person();
$johnSmith = new Person();
$wuhan = new City();
$interaction = $wuhan->interactionBetween($johnSmith, $janeDoe);
$interaction->propagate($covid19);
/* Jane will not be affected since the interaction
prevents from propagating the virus */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment