EduardoGR adding strategy context in order to complete the pattern

This commit is contained in:
egarcia
2017-10-31 03:51:44 +01:00
parent 3ea7462991
commit 16f09e99e7
3 changed files with 28 additions and 50 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace DesignPatterns\Behavioral\Strategy;
class Context
{
/**
* @var ComparatorInterface
*/
private $comparator;
public function __construct(ComparatorInterface $comparator)
{
$this->comparator = $comparator;
}
public function executeStrategy(array $elements) : array
{
uasort($elements, [$this->comparator, 'compare']);
return $elements;
}
}