{"id":"6b08bd3a80884893657cc9b4","slug":"memento","title":"Memento: a state snapshot without breaking encapsulation","summary":"The Memento pattern through a menu editor: Halina saves versions of the menu and returns to them with one click, while the history keeps snapshots without seeing what is inside. Copies instead of references, memory costs and code in five languages.","servedLang":"en","availableLangs":["pl","en"],"topics":["memento"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","behavioral","memento","undo","snapshots","encapsulation"],"level":"intermediate","kind":"article","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":13,"stats":{"views":2,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:14:02.576Z","updatedAt":"2026-11-27T13:10:08.081Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"violet","background":"hex","weaveResources":true,"toc":"right"},"seoDescription":"The Memento design pattern in C#, TypeScript, Java, Go and Python: state snapshots, undo, the caretaker history, encapsulation and memory costs.","wordCount":2438,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Halina is putting together the autumn menu in the admin panel. She raises prices, adds pierogi with black pudding, deletes the potato-and-cheese ones by mistake – and wants to go back to the version from five minutes ago. "},{"type":"text","text":"Memento","marks":[{"type":"bold"}]},{"type":"text","text":" lets you save a snapshot of an object's state and restore it later, while nobody but the object itself looks inside."}]},{"type":"callout","attrs":{"variant":"tip","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The "},{"type":"text","text":"originator","marks":[{"type":"bold"}]},{"type":"text","text":" creates a snapshot of its own state and knows how to restore it."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The "},{"type":"text","text":"caretaker","marks":[{"type":"bold"}]},{"type":"text","text":" stores snapshots – the history, versions – but "},{"type":"text","text":"does not know what they contain","marks":[{"type":"bold"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A snapshot has to be a "},{"type":"text","text":"copy","marks":[{"type":"bold"}]},{"type":"text","text":", not a reference to the live state, and ideally immutable."}]}]}]}]},{"type":"stats","attrs":{"items":[{"value":"3","label":"roles in the pattern","hint":"originator, memento, caretaker"},{"value":"0","label":"menu fields visible to the history","hint":"only a label and the save time"},{"value":"1","label":"typical bug","hint":"a snapshot sharing a collection with the original"}]}},{"type":"heading","attrs":{"level":2,"id":"the-problem-a-history-that-knows-too-much"},"content":[{"type":"text","text":"The problem: a history that knows too much"}]},{"type":"paragraph","content":[{"type":"text","text":"The first version of the editor kept copies of the menu draft in an array:"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"menu-editor-before.ts"},"content":[{"type":"text","text":"class MenuDraft {\n  title = 'Autumn menu';\n  prices = new Map<string, number>(); // public, so the editor can copy it\n}\n\nconst versions: { title: string; prices: Map<string, number> }[] = [];\n\nfunction saveVersion(draft: MenuDraft): void {\n  versions.push({ title: draft.title, prices: draft.prices }); // bug: same Map, not a copy\n}\n\nfunction undo(draft: MenuDraft): void {\n  const last = versions.pop();\n  if (last) Object.assign(draft, last); // the editor knows every field of the draft\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"There are two problems here. First, the editor knows every field of the draft ("},{"type":"text","text":"title","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"prices","marks":[{"type":"code"}]},{"type":"text","text":"), so every new field – a photo, allergens, the order of dishes – requires changes in the history. The draft also has to expose its fields publicly, just so they can be copied. Second, the \"copy\" is a reference to the same price map: every later change to the draft silently changes the saved versions too, so undo restores… the current state."}]},{"type":"heading","attrs":{"level":2,"id":"the-solution-let-the-object-take-its-own-pictures"},"content":[{"type":"text","text":"The solution: let the object take its own pictures"}]},{"type":"paragraph","content":[{"type":"text","text":"The menu draft (the originator) gets two methods: "},{"type":"text","text":"save(label)","marks":[{"type":"code"}]},{"type":"text","text":" creates a snapshot, and "},{"type":"text","text":"restore(snapshot)","marks":[{"type":"code"}]},{"type":"text","text":" restores the state from it. The snapshot contains a copy of everything the draft needs to rebuild itself, but exposes only a label and the save time to the outside. The history (the caretaker) keeps a stack of snapshots and hands them back to the draft on request – without understanding what is inside."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  actor H as Halina\n  participant E as MenuHistory (caretaker)\n  participant D as MenuDraft (originator)\n  participant S as Snapshot (memento)\n  H->>E: save(\"price rise\")\n  E->>D: save(\"price rise\")\n  D->>S: copy of title and prices\n  D-->>E: snapshot (opaque)\n  H->>D: remove(\"Ruskie\")\n  Note over D: a mistake!\n  H->>E: undo()\n  E->>D: restore(snapshot)\n  D->>S: read the state (only the originator has access)","caption":"Saving a version and undoing a mistake"}},{"type":"diagram","attrs":{"kind":"mermaid","code":"classDiagram\n  direction LR\n  class MenuDraft {\n    -title\n    -prices\n    +save(label) MenuSnapshot\n    +restore(snapshot)\n  }\n  class MenuSnapshot {\n    <<interface>>\n    +label\n    +takenAt\n  }\n  class Snapshot {\n    -title\n    -prices\n  }\n  class MenuHistory {\n    -snapshots: Stack~MenuSnapshot~\n    +save(label)\n    +undo()\n  }\n  MenuDraft ..> Snapshot : creates and reads\n  MenuSnapshot <|.. Snapshot\n  MenuHistory o--> MenuSnapshot : stores","caption":"Participants of the Memento pattern"}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Role"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"In the example"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Responsibility"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Originator"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"MenuDraft","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"creates a snapshot of its state and restores itself from it"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Memento"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Snapshot","marks":[{"type":"code"}]},{"type":"text","text":" behind the "},{"type":"text","text":"MenuSnapshot","marks":[{"type":"code"}]},{"type":"text","text":" interface"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"an immutable copy of the state; only metadata on the outside"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Caretaker"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"MenuHistory","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"stores snapshots, decides when to save and undo"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"implementation-in-five-languages"},"content":[{"type":"text","text":"Implementation in five languages"}]},{"type":"paragraph","content":[{"type":"text","text":"The most interesting part is "},{"type":"text","text":"how","marks":[{"type":"bold"}]},{"type":"text","text":" each language hides the snapshot's contents. C# and Java use a private nested type behind a public interface. TypeScript keeps the state in the module, in a "},{"type":"text","text":"WeakMap","marks":[{"type":"code"}]},{"type":"text","text":" only the draft can access. Go relies on package-level encapsulation (lower-case fields), and Python on the underscore convention and an immutable copy."}]},{"type":"codeGroup","attrs":{"title":"Memento – menu editor"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"MenuDraft.cs"},"content":[{"type":"text","text":"var draft = new MenuDraft(\"Autumn menu\");\nvar menuHistory = new MenuHistory(draft);\n\ndraft.SetPrice(\"Ruskie\", 28m);\nmenuHistory.Save(\"base prices\");\ndraft.SetPrice(\"Ruskie\", 32m);\ndraft.SetPrice(\"With black pudding\", 35m);\nmenuHistory.Save(\"price rise\");\ndraft.Remove(\"Ruskie\");   // oops\nmenuHistory.Undo();           // back to \"price rise\"\nConsole.WriteLine(draft); // Autumn menu: Ruskie 32, With black pudding 35\n\n// All the caretaker may see: a label and a time, never the menu itself.\npublic interface IMenuSnapshot\n{\n    string Label { get; }\n    DateTime TakenAt { get; }\n}\n\npublic sealed class MenuDraft(string title)\n{\n    private string _title = title;\n    private readonly Dictionary<string, decimal> _prices = new();\n\n    public void SetPrice(string dish, decimal price) => _prices[dish] = price;\n    public void Remove(string dish) => _prices.Remove(dish);\n\n    // Copy the dictionary – a snapshot must not share mutable state with the draft.\n    public IMenuSnapshot Save(string label) => new Snapshot(label, DateTime.UtcNow, _title, new(_prices));\n\n    public void Restore(IMenuSnapshot snapshot)\n    {\n        var s = (Snapshot)snapshot; // only the originator knows the real type\n        _title = s.Title;\n        _prices.Clear();\n        foreach (var (dish, price) in s.Prices) _prices[dish] = price;\n    }\n\n    public override string ToString() => $\"{_title}: {string.Join(\", \", _prices.Select(p => $\"{p.Key} {p.Value}\"))}\";\n\n    // Nested and private: nobody outside MenuDraft can read the saved state.\n    private sealed record Snapshot(string Label, DateTime TakenAt, string Title, Dictionary<string, decimal> Prices)\n        : IMenuSnapshot;\n}\n\n// The caretaker stores snapshots without looking inside.\npublic sealed class MenuHistory(MenuDraft draft)\n{\n    private readonly Stack<IMenuSnapshot> _snapshots = new();\n\n    public void Save(string label) => _snapshots.Push(draft.Save(label));\n\n    public void Undo()\n    {\n        if (_snapshots.TryPop(out var snapshot)) draft.Restore(snapshot);\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"menu-draft.ts"},"content":[{"type":"text","text":"type MenuState = { title: string; prices: Map<string, number> };\n\n/** Opaque handle: the caretaker sees only a label and a time. */\ninterface MenuSnapshot {\n  readonly label: string;\n  readonly takenAt: Date;\n}\n\n// Module-private storage: only MenuDraft can turn a snapshot back into state.\nconst saved = new WeakMap<MenuSnapshot, MenuState>();\n\nclass MenuDraft {\n  private prices = new Map<string, number>();\n  constructor(private title: string) {}\n\n  setPrice(dish: string, price: number): void { this.prices.set(dish, price); }\n  remove(dish: string): void { this.prices.delete(dish); }\n\n  save(label: string): MenuSnapshot {\n    const snapshot = Object.freeze({ label, takenAt: new Date() });\n    saved.set(snapshot, { title: this.title, prices: new Map(this.prices) }); // copy, not a reference\n    return snapshot;\n  }\n\n  restore(snapshot: MenuSnapshot): void {\n    const state = saved.get(snapshot);\n    if (!state) throw new Error('Unknown snapshot');\n    this.title = state.title;\n    this.prices = new Map(state.prices);\n  }\n\n  toString(): string {\n    return `${this.title}: ${[...this.prices].map(([d, p]) => `${d} ${p}`).join(', ')}`;\n  }\n}\n\nclass MenuHistory {\n  private readonly snapshots: MenuSnapshot[] = [];\n  constructor(private readonly draft: MenuDraft) {}\n\n  save(label: string): void { this.snapshots.push(this.draft.save(label)); }\n\n  undo(): void {\n    const snapshot = this.snapshots.pop();\n    if (snapshot) this.draft.restore(snapshot);\n  }\n}\n\nconst draft = new MenuDraft('Autumn menu');\nconst menuHistory = new MenuHistory(draft);\ndraft.setPrice('Ruskie', 28);\nmenuHistory.save('base prices');\ndraft.setPrice('Ruskie', 32);\ndraft.setPrice('With black pudding', 35);\nmenuHistory.save('price rise');\ndraft.remove('Ruskie'); // oops\nmenuHistory.undo();\nconsole.log(draft.toString()); // Autumn menu: Ruskie 32, With black pudding 35"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"MenuEditor.java"},"content":[{"type":"text","text":"import java.time.Instant;\nimport java.util.ArrayDeque;\nimport java.util.Deque;\nimport java.util.LinkedHashMap;\nimport java.util.Map;\n\n// All the caretaker may see: a label and a time, never the menu itself.\ninterface MenuSnapshot {\n    String label();\n    Instant takenAt();\n}\n\nclass MenuDraft {\n    private String title;\n    private final Map<String, Integer> prices = new LinkedHashMap<>();\n\n    MenuDraft(String title) { this.title = title; }\n\n    void setPrice(String dish, int price) { prices.put(dish, price); }\n    void remove(String dish) { prices.remove(dish); }\n\n    // Private nested record: only MenuDraft can read the saved state.\n    private record Snapshot(String label, Instant takenAt, String title, Map<String, Integer> prices)\n        implements MenuSnapshot {}\n\n    MenuSnapshot save(String label) {\n        return new Snapshot(label, Instant.now(), title, new LinkedHashMap<>(prices)); // copy!\n    }\n\n    void restore(MenuSnapshot snapshot) {\n        var s = (Snapshot) snapshot;\n        title = s.title();\n        prices.clear();\n        prices.putAll(s.prices());\n    }\n\n    @Override public String toString() { return title + \": \" + prices; }\n}\n\n// The caretaker stores snapshots without looking inside.\nclass MenuHistory {\n    private final Deque<MenuSnapshot> snapshots = new ArrayDeque<>();\n    private final MenuDraft draft;\n\n    MenuHistory(MenuDraft draft) { this.draft = draft; }\n\n    void save(String label) { snapshots.push(draft.save(label)); }\n\n    void undo() { if (!snapshots.isEmpty()) draft.restore(snapshots.pop()); }\n}\n\npublic class MenuEditor {\n    public static void main(String[] args) {\n        var draft = new MenuDraft(\"Autumn menu\");\n        var menuHistory = new MenuHistory(draft);\n        draft.setPrice(\"Ruskie\", 28);\n        menuHistory.save(\"base prices\");\n        draft.setPrice(\"Ruskie\", 32);\n        draft.setPrice(\"With black pudding\", 35);\n        menuHistory.save(\"price rise\");\n        draft.remove(\"Ruskie\"); // oops\n        menuHistory.undo();\n        System.out.println(draft); // Autumn menu: {Ruskie=32, With black pudding=35}\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"menu.go"},"content":[{"type":"text","text":"package main\n\nimport (\n\t\"fmt\"\n\t\"maps\"\n\t\"time\"\n)\n\n// Snapshot has only unexported state fields: code outside this package\n// (e.g. a caretaker in another package) can store it but not read the menu.\ntype Snapshot struct {\n\tLabel   string\n\tTakenAt time.Time\n\ttitle   string\n\tprices  map[string]int\n}\n\ntype MenuDraft struct {\n\ttitle  string\n\tprices map[string]int\n}\n\nfunc NewMenuDraft(title string) *MenuDraft {\n\treturn &MenuDraft{title: title, prices: map[string]int{}}\n}\n\nfunc (m *MenuDraft) SetPrice(dish string, price int) { m.prices[dish] = price }\nfunc (m *MenuDraft) Remove(dish string)              { delete(m.prices, dish) }\n\n// Save copies the map – a snapshot must not share mutable state with the draft.\nfunc (m *MenuDraft) Save(label string) Snapshot {\n\treturn Snapshot{label, time.Now(), m.title, maps.Clone(m.prices)}\n}\n\nfunc (m *MenuDraft) Restore(s Snapshot) {\n\tm.title, m.prices = s.title, maps.Clone(s.prices)\n}\n\n// MenuHistory is the caretaker.\ntype MenuHistory struct {\n\tdraft     *MenuDraft\n\tsnapshots []Snapshot\n}\n\nfunc (h *MenuHistory) Save(label string) { h.snapshots = append(h.snapshots, h.draft.Save(label)) }\n\nfunc (h *MenuHistory) Undo() {\n\tif n := len(h.snapshots); n > 0 {\n\t\th.draft.Restore(h.snapshots[n-1])\n\t\th.snapshots = h.snapshots[:n-1]\n\t}\n}\n\nfunc main() {\n\tdraft := NewMenuDraft(\"Autumn menu\")\n\tmenuHistory := &MenuHistory{draft: draft}\n\tdraft.SetPrice(\"Ruskie\", 28)\n\tmenuHistory.Save(\"base prices\")\n\tdraft.SetPrice(\"Ruskie\", 32)\n\tdraft.SetPrice(\"With black pudding\", 35)\n\tmenuHistory.Save(\"price rise\")\n\tdraft.Remove(\"Ruskie\") // oops\n\tmenuHistory.Undo()\n\tfmt.Println(draft.title, draft.prices) // Autumn menu map[Ruskie:32 With black pudding:35]\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"menu_draft.py"},"content":[{"type":"text","text":"from dataclasses import dataclass, field\nfrom datetime import datetime, timezone\nfrom types import MappingProxyType\nfrom typing import Mapping\n\n\n@dataclass(frozen=True)\nclass MenuSnapshot:\n    \"\"\"The caretaker should only use label and taken_at; the rest is the originator's business.\"\"\"\n    label: str\n    taken_at: datetime\n    _title: str = field(repr=False)\n    _prices: Mapping[str, int] = field(repr=False)\n\n\nclass MenuDraft:\n    def __init__(self, title: str) -> None:\n        self._title = title\n        self._prices: dict[str, int] = {}\n\n    def set_price(self, dish: str, price: int) -> None:\n        self._prices[dish] = price\n\n    def remove(self, dish: str) -> None:\n        self._prices.pop(dish, None)\n\n    def save(self, label: str) -> MenuSnapshot:\n        # Copy and freeze: the snapshot must not share mutable state with the draft.\n        frozen = MappingProxyType(dict(self._prices))\n        return MenuSnapshot(label, datetime.now(timezone.utc), self._title, frozen)\n\n    def restore(self, snapshot: MenuSnapshot) -> None:\n        self._title = snapshot._title\n        self._prices = dict(snapshot._prices)\n\n    def __str__(self) -> str:\n        return f\"{self._title}: \" + \", \".join(f\"{d} {p}\" for d, p in self._prices.items())\n\n\nclass MenuHistory:\n    \"\"\"The caretaker stores snapshots without looking inside.\"\"\"\n\n    def __init__(self, draft: MenuDraft) -> None:\n        self._draft = draft\n        self._snapshots: list[MenuSnapshot] = []\n\n    def save(self, label: str) -> None:\n        self._snapshots.append(self._draft.save(label))\n\n    def undo(self) -> None:\n        if self._snapshots:\n            self._draft.restore(self._snapshots.pop())\n\n\ndraft = MenuDraft(\"Autumn menu\")\nmenu_history = MenuHistory(draft)\ndraft.set_price(\"Ruskie\", 28)\nmenu_history.save(\"base prices\")\ndraft.set_price(\"Ruskie\", 32)\ndraft.set_price(\"With black pudding\", 35)\nmenu_history.save(\"price rise\")\ndraft.remove(\"Ruskie\")  # oops\nmenu_history.undo()\nprint(draft)  # Autumn menu: Ruskie 32, With black pudding 35"}]}]}]},"toc":[{"id":"the-problem-a-history-that-knows-too-much","text":"The problem: a history that knows too much","level":2,"locked":false},{"id":"the-solution-let-the-object-take-its-own-pictures","text":"The solution: let the object take its own pictures","level":2,"locked":false},{"id":"implementation-in-five-languages","text":"Implementation in five languages","level":2,"locked":false},{"id":"what-does-the-history-cost","text":"What does the history cost?","level":2,"locked":true},{"id":"memento-vs-undo-through-command","text":"Memento vs undo through Command","level":2,"locked":true},{"id":"when-to-use-it-and-when-not-to","text":"When to use it and when not to","level":2,"locked":true},{"id":"related-patterns","text":"Related patterns","level":2,"locked":true},{"id":"in-practice","text":"In practice","level":2,"locked":true},{"id":"test-yourself","text":"Test yourself","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":36,"visibleBlocks":15,"resources":[{"id":"6b0857c53c96f2d34d0b4887","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=ZXAt8AP3DnY","embedUrl":"https://www.youtube-nocookie.com/embed/ZXAt8AP3DnY","title":"The Memento Pattern: Saving State Without Breaking Encapsulation","description":"👨🏻‍💻 Join me in Utrecht next year for an in-person Software Design Retreat! Design, discuss, and learn alongside fellow developers. Join the waitlist: https://arjancodes.com/retreat. 🧱 Build software that lasts. Join the Software Design Mastery program → https://arjan.codes/mastery. Undo…","author":"ArjanCodes","thumbnailUrl":"https://i.ytimg.com/vi/ZXAt8AP3DnY/hqdefault.jpg","durationSec":null,"lang":"en","topics":["memento"],"techs":["python"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"youtube-rss","publishedAt":"2026-10-09T15:00:08.000Z","popularity":72,"verifiedAt":"2026-11-26T10:54:43.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:07.481Z","updatedAt":"2026-11-26T16:01:07.481Z"},{"id":"6b0857bf3c96f2d34d0b42d4","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/memento","embedUrl":null,"title":"Pamiątka / Memento","description":"Pamiątka to behawioralny wzorzec projektowy pozwalający zapisywać i przywracać wcześniejszy stan obiektu bez ujawniania szczegółów jego implementacji.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["memento"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":60,"verifiedAt":"2026-11-26T11:26:13.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857bb3c96f2d34d0b4009","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/design-patterns-part-4-adapter-facade-and-memento/id769189585?i=1000378375293","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id769189585?i=1000378375293","title":"Design Patterns Part 4 – Adapter, Facade, and Memento","description":"Part 4 of our design patterns series, this time up it's Adapters, Facades, and Mementos. Oh, an which tech luminary would make the best head of state!","author":"Coding Blocks","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts113/v4/f0/b6/68/f0b6682f-e8bc-181c-95a9-0756ddf63d6e/mza_3128980961332034780.jpg/600x600bb.jpg","durationSec":4452,"lang":"en","topics":["adapter","facade","memento"],"techs":["general"],"tags":["podcast","design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2015-07-26T12:00:44.000Z","popularity":46,"verifiedAt":"2026-11-26T10:57:39.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:57.868Z","updatedAt":"2026-11-26T16:00:57.868Z"},{"id":"6b0857c33c96f2d34d0b4658","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL6030812W","embedUrl":null,"title":"Design Patterns: Elements of Reusable Object-Oriented Software","description":"","author":"Erich Gamma, John Vlissides, Richard Helm, Ralph Johnson","thumbnailUrl":"https://covers.openlibrary.org/b/id/6601119-L.jpg","durationSec":null,"lang":"en","topics":["factory-method","abstract-factory","builder","prototype","singleton","adapter","bridge","composite","decorator","facade","flyweight","proxy","chain-of-responsibility","command","iterator","mediator","memento","observer","state","strategy","template-method","visitor"],"techs":["general"],"tags":["book","design-patterns"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"1995-01-01T00:00:00.000Z","popularity":71,"verifiedAt":"2026-11-26T11:00:08.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:04.995Z","updatedAt":"2026-11-26T16:01:04.995Z"}],"challenges":[{"id":"6b093ddfbd4755deb67ee09b","slug":"serialize-binary-tree","title":"Serialize a binary tree","summary":"Write a binary tree to a string and rebuild it – with empty subtrees, negative numbers and trees thousands of levels deep. Format design, BFS and the recursion trap.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"algorithms","status":"published","difficulty":"hard","topics":["memento"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["trees","binary-tree","bfs","dfs","serialization","design"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":40,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:55.586Z"},{"id":"6b093dc191bd8fbaf2a0c8c8","slug":"game-checkpoint-memento","title":"Game checkpoints","summary":"Saving and restoring a hero's state with Memento – immutable snapshots without shared lists, a caretaker with limited capacity and protection against loading someone else's save.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"pattern","status":"published","difficulty":"easy","topics":["memento"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["memento","snapshots","undo","immutability","behavioral"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":10,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:25.224Z"}],"attachments":[],"hasCode":true,"repoUrl":null,"series":[{"slug":"gof-behavioral","title":"GoF behavioral patterns","items":[{"slug":"strategy","title":"Strategy: interchangeable algorithms instead of an if-else ladder","current":false},{"slug":"observer","title":"Observer: notify everyone without knowing anyone","current":false},{"slug":"command","title":"Command: a request wrapped in an object","current":false},{"slug":"state","title":"State: an object that changes behaviour with its life stage","current":false},{"slug":"template-method","title":"Template Method: a fixed recipe, interchangeable ingredients","current":false},{"slug":"iterator","title":"Iterator: walking a collection without looking inside","current":false},{"slug":"chain-of-responsibility","title":"Chain of Responsibility: pass it on until someone takes care of it","current":false},{"slug":"mediator","title":"Mediator: components talk through a coordinator","current":false},{"slug":"memento","title":"Memento: a state snapshot without breaking encapsulation","current":true},{"slug":"visitor","title":"Visitor: new operations without changing classes","current":false}]}],"prev":{"slug":"mediator","title":"Mediator: components talk through a coordinator"},"next":{"slug":"visitor","title":"Visitor: new operations without changing classes"},"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":68,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":38}]}}