<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 問題 Problem 你想記錄一個對象的變化。 You want to anticipate the reversion of changes to an object. ## 方法 Solution 使用[備忘錄模式](http://en.wikipedia.org/wiki/Memento_pattern)來跟蹤一個對象的變化。使用這個模式的類會返回一個`memento`對象,可以保存到其他地方。 Use the?[Memento pattern](http://en.wikipedia.org/wiki/Memento_pattern)?to track changes to an object. The class using the pattern will export a?`memento`?object stored elsewhere. 例如,你有個程序,用戶可以編輯文本文件,他們應該有需要取消他們最后一次編輯。你可以在用戶改變文件之前保存當前的狀態,之后可以進行恢復。 If you have application where the user can edit a text file, for example, they may want to undo their last action. You can save the current state of the file before the user changes it and then roll back to that at a later point. ~~~ class PreserveableText class Memento constructor: (@text) -> constructor: (@text) -> save: (newText) -> memento = new Memento @text @text = newText memento restore: (memento) -> @text = memento.text pt = new PreserveableText "The original string" pt.text # => "The original string" memento = pt.save "A new string" pt.text # => "A new string" pt.save "Yet another string" pt.text # => "Yet another string" pt.restore memento pt.text # => "The original string" ~~~ ## 討論 Discussion 由`PreserveableText#save`返回的備忘錄對象單獨保管著重要的狀態信息。 你甚至可以把這個備忘錄對象序列化,便于在硬盤上維護一個“撤銷”緩沖區,或者remotely for such data-intensive objects as edited images。 The Memento object returned by?`PreserveableText#save`?stores the important state information separately for safe-keeping. You could even serialize this Memento in order to maintain an “undo” buffer on the hard disk or remotely for such data-intensive objects as edited images.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看