Python Forum
Memento Pattern - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: Memento Pattern (/thread-22747.html)



Memento Pattern - amb85 - Nov-25-2019

I'm wondering what the applicability of the Memento design pattern is in Python.

The intent of the pattern is to capture and externalise the internal state of an object without breaking encapsulation, so that the object can be restored to that state later. Implementation typically relies on being able to declare public and private methods/attributes on classes.

My question arises because in Python, it is only by convention that we consider an attribute/method to be private. Does the lack of language enforced visibility modifiers invalidate memento as a design pattern in Python, or is it sufficient to assume that potential clients will adhere to convention?


RE: Memento Pattern - Larz60+ - Nov-25-2019

haven't tried it, but see: https://gist.github.com/fabiobatalha/5404977


RE: Memento Pattern - amb85 - Nov-25-2019

(Nov-25-2019, 04:25 PM)Larz60+ Wrote: haven't tried it, but see: https://gist.github.com/fabiobatalha/5404977

A tidy implementation. Thanks for sharing.