RefactoringGuru / design-patterns-php

Design Pattern Examples in PHP

Home Page:https://refactoring.guru/design-patterns/php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memento pattern - getState method not defined into interface

sukhoy94 opened this issue · comments

Hello, I have noticed one tricky thing in a conceptual example.
Here is an interface:

interface Memento
{
    public function getName(): string;    
    public function getDate(): string;
}

and here is restore() method from originator:

public function restore(Memento $memento): void
{
    $this->state = $memento->getState();
    echo "Originator: My state has changed to: {$this->state}\n";
}

I don't really understand how we can call getState method if interface doesn't declare it ?

Hi!

Please see https://refactoring.guru/design-patterns/memento "Implementation based on an intermediate interface"