Skip to content

Instantly share code, notes, and snippets.

@mcsee

mcsee/decorated.php

Last active Jan 27, 2021
Embed
What would you like to do?
<?
final class Calculator {
function computeSomething() {
// Do Real work here since I am Compute!
}
}
//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