Last active
September 6, 2023 00:41
-
-
Save mcsee/ce98c6db785d947e77790c3cc6b4bad0 to your computer and use it in GitHub Desktop.
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
<? | |
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