Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 21, 2023 14:52
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/dd988af705942cfafd5811df60acaed2 to your computer and use it in GitHub Desktop.
Save mcsee/dd988af705942cfafd5811df60acaed2 to your computer and use it in GitHub Desktop.
<?
final class Calculator {
private $cachedResults;
function computeSomething() {
if (isset($this->cachedResults)) {
return $this->cachedResults;
}
$this->cachedResults = $this->logAndComputeSomething();
}
private function logAndComputeSomething() {
$this->logProcessStart();
$result = $this->basicComputeSomething();
$this->logProcessEnd();
return $result;
}
private function basicComputeSomething() {
// Do Real work here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment