Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active September 6, 2023 00:41
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/ce98c6db785d947e77790c3cc6b4bad0 to your computer and use it in GitHub Desktop.
Save mcsee/ce98c6db785d947e77790c3cc6b4bad0 to your computer and use it in GitHub Desktop.
<?
final class Calculator {
function computeSomething() {
// Do Real work here since I am the compute method
}
}
// Clean and cohesive class, single responsibility
final class CalculatorDecoratorCache {
private $cachedResults;
private $decorated;
function computeSomething() {
if (isset($this->cachedResults)) {
return $this->cachedResults;
}
$this->cachedResults = $this->decorated->computeSomething();
}
}
final class CalculatorDecoratorLogger {
private $decorated;
function computeSomething() {
$this->logProcessStart();
$result = $this->decorated->computeSomething();
$this->logProcessEnd();
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment