Files
DesignPatternsPHP/Memento/Originator.php
2014-04-13 19:51:37 +04:00

34 lines
588 B
PHP

<?php
namespace DesignPatterns\Memento;
class Originator
{
/* @var string */
private $state;
// The class could also contain additional data that is not part of the
// state saved in the memento..
/**
* @param string $state
*/
public function setState($state)
{
$this->state = $state;
}
/**
* @return Memento
*/
public function saveToMemento()
{
return new Memento($this->state);
}
public function restoreFromMemento(Memento $memento)
{
$this->state = $memento->getState();
}
}