Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我对这种模式不了解的一件事。为什么 Memento 对象没有构造函数和 getState() 方法?创建 Memento 后何时设置它的状态才有意义?这不是改变过去吗?
您不应该在 Memento 类中有 setState 方法。这没有道理。Memento 只是 Caretaker 用来恢复 Originator 状态的令牌。如果看守者想要一个带有新状态信息的新纪念品,它应该从 Originator 那里得到它。
这是一个很好的例子。
keeps getting longer and pushes all the content below it down