HoangYell / public

0 stars 0 forks source link

bp9-file-history-learn-design-pattern-from-simple-things/ #4

Closed utterances-bot closed 1 year ago

utterances-bot commented 1 year ago

BP9 - File History - Learn Design Pattern From Simple Things

Undo and redo are common features in editing software. They look simple on the surface, but how do they work internally? How do you design structure and behavior for them?

https://hoangyell.com/bp9-file-history-learn-design-pattern-from-simple-things/

Hoang-Yell commented 1 year ago

What do you mean by

“This pattern allows an object to save and restore its state without exposing its internal details”

I don’t see any exposure here.

HoangYell commented 1 year ago

@Hoang-Yell What I mean is that the File History design pattern encapsulates the state of the Photoshop object in a File object, which is then stored by the SSDStorage object. The Photoshop object does not need to know how the File object is implemented or how the SSDStorage object manages the file history. It only needs to know how to create and load a File object. Similarly, the SSDStorage object does not need to know how the Photoshop object edits the content or how the File object stores it. It only needs to know how to save and pop a File object.

This way, the internal details of each class are hidden from each other, and only the necessary interfaces are exposed.