refactored State pattern example

This commit is contained in:
Dominik Liebler
2018-06-14 22:49:28 +02:00
parent ea85485b85
commit 93d4ebf90f
11 changed files with 133 additions and 113 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace DesignPatterns\Behavioral\State;
class OrderContext
{
/**
* @var State
*/
private $state;
public static function create(): OrderContext
{
$order = new self();
$order->state = new StateCreated();
return $order;
}
public function setState(State $state)
{
$this->state = $state;
}
public function proceedToNext()
{
$this->state->proceedToNext($this);
}
public function toString()
{
return $this->state->toString();
}
}