Skip to content

Memento pattern realworld example #43

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

drissboumlik
Copy link
Contributor

No description provided.

@neochief
Copy link
Contributor

Hi Driss!

Thanks for the example. To be honest with you, I hardly see the point of having such an order history class in place (why do you ever revert the order state?). I've been working with lots of ordering/payments systems, none of them had anything like this.

In my opinion, a good example for this pattern should play around these two scenarios:

  1. The memento must have sensitive info (so that the problem would be not letting caretaker access that info)
  2. OR there should be too many types of various mementos (so that the problem would be not making caretaker depend on dozens specific types of mementos).

A feature of a good example is also that the reader doesn't think "why do you have to have all this classes and not just two arrays". This is super hard thing to achieve with the real world examples, ha-ha.

Let me know what you think.

@drissboumlik
Copy link
Contributor Author

hmm, I see
what about a shopping cart abandonment & recovery (saving cart states so users can return later to complete purchases)
or an admin dashboard where users can update the site configuration, the system should allow rollbacks.

@neochief
Copy link
Contributor

Man, site config with the ability to rollback is very promising idea!

@drissboumlik
Copy link
Contributor Author

something like this :

// Originator
class ConfigManager { }

// The Memento interface
interface ConfigMemento {}

// The Concrete Memento
class ConfigSnapshot implements ConfigMemento {}

class ConfigHistory {}

// ....
$config = new ConfigManager([
    'maintenance_mode' => false,
    'theme' => 'light',
    'seo' => ['title' => 'My Website', 'description' => 'Welcome to my site!'],
    'debug' => false,
    'max_users' => 1000
]);

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

Successfully merging this pull request may close these issues.

2 participants