# Design pattern for undo operation with Makie

**URL:** <https://discourse.julialang.org/t/design-pattern-for-undo-operation-with-makie/102868>\
**Category:** General Usage\
**Tags:** question, package, makie\
**Created:** [August 16, 2023, 4:05pm UTC](https://discourse.julialang.org/t/design-pattern-for-undo-operation-with-makie/102868 "2023-08-16T16:05:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 16, 2023, 4:05pm UTC](https://discourse.julialang.org/t/design-pattern-for-undo-operation-with-makie/102868/1 "2023-08-16T16:05:15Z")

</div>

We have GUI program where it would be useful to have an UNDO button: [Add undo button · Issue #7 · bradcarman/ModelingToolkitDesigner.jl · GitHub](https://github.com/bradcarman/ModelingToolkitDesigner.jl/issues/7)

Is there any suggestion how to implement this?

EDIT: Article related to C#: [Multilevel Undo and Redo Implementation in C# - Part I (Using Single Object Representing Change Approach) - CodeProject](https://www.codeproject.com/Articles/33371/Multilevel-Undo-and-Redo-Implementation-in-C-Part)

---

<div class="post-metadata">

**Author:** ![grunst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grunst/32/9271_2.png) [@grunst](https://discourse.julialang.org/u/grunst)\
**Post date:** [August 16, 2023, 8:35pm UTC](https://discourse.julialang.org/t/design-pattern-for-undo-operation-with-makie/102868/2 "2023-08-16T20:35:37Z")

</div>

These C++ talks by Sean Parent might also be useful for inspiration for undo/redo implementations:

- [Inheritance Is The Base Class of Evil](https://www.youtube.com/watch?v=bIhUE5uUFOA)
- [Better code: Runtime polymorphism](https://www.youtube.com/watch?v=QGcVXgEVMJg)
- [Value Semantics and Concepts-based Polymorphism](https://www.youtube.com/watch?v=_BpMYeUFXv8)

---

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [August 18, 2023, 4:30pm UTC](https://discourse.julialang.org/t/design-pattern-for-undo-operation-with-makie/102868/3 "2023-08-18T16:30:00Z")

</div>

Guess the classic OOP solution would be the [memento pattern](https://en.wikipedia.org/wiki/Memento_pattern). A particularly easy approach to achieve that, would be by using [immutable data structures](https://en.wikipedia.org/wiki/Persistent_data_structure) which can basically act as there own snapshot at any time.  
Another approach would be to reify actions into a data type and store the sequence of all applied actions, which can then be (partially) replayed at will later on, i.e., as in the [command pattern](https://en.wikipedia.org/wiki/Command_pattern) which is also common to support undo/redo operations.  
Finally, [here](https://mishadoff.com/blog/clojure-design-patterns/) is a nice wrap-up showing how these (as well as most other OOP patterns) become easier in a language (Clojure) with first class functions and immutable data structures.
