Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memento Pattern
#1
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?
Reply
#2
haven't tried it, but see: https://gist.github.com/fabiobatalha/5404977
Reply
#3
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020