Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memento pattern - getState method not defined into interface #37

Open
sukhoy94 opened this issue Nov 13, 2022 · 1 comment
Open

Memento pattern - getState method not defined into interface #37

sukhoy94 opened this issue Nov 13, 2022 · 1 comment

Comments

@sukhoy94
Copy link

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 ?

@neochief
Copy link
Contributor

Hi!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants