成都城乡建设部网站首页网站和网页的区别在于

当前位置: 首页 > news >正文

成都城乡建设部网站首页,网站和网页的区别在于,wordpress插件密钥实现,天津大型网站设计公司引言:对象状态的时空穿越 在软件开发中,我们经常遇到需要保存和恢复对象状态的场景: 文本编辑器的撤销/重做功能游戏进度的存档与读档事务操作的回滚机制表单数据的草稿保存备忘录模式正是为解决这类问题而生的设计模式。它提供了一种在不破坏封装性的前提下捕获并外部化对…引言:对象状态的时空穿越 在软件开发中,我们经常遇到需要保存和恢复对象状态的场景: 文本编辑器的撤销/重做功能游戏进度的存档与读档事务操作的回滚机制表单数据的草稿保存备忘录模式正是为解决这类问题而生的设计模式。它提供了一种在不破坏封装性的前提下捕获并外部化对象的内部状态,以便在需要时恢复对象到先前状态的能力。本文将深入剖析备忘录模式的原理、实现及高级应用场景。 一、模式定义与核心思想 1.1 官方定义 备忘录模式 (Memento Pattern):在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样以后就可将该对象恢复到原先保存的状态。 1.2 设计哲学 #mermaid-svg-TY3voL6sUTgEKCed {font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-TY3voL6sUTgEKCed .error-icon{fill:#552222;}#mermaid-svg-TY3voL6sUTgEKCed .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-TY3voL6sUTgEKCed .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-TY3voL6sUTgEKCed .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-TY3voL6sUTgEKCed .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-TY3voL6sUTgEKCed .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-TY3voL6sUTgEKCed .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-TY3voL6sUTgEKCed .marker{fill:#333333;stroke:#333333;}#mermaid-svg-TY3voL6sUTgEKCed .marker.cross{stroke:#333333;}#mermaid-svg-TY3voL6sUTgEKCed svg{font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-TY3voL6sUTgEKCed .label{font-family:“trebuchet ms”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-TY3voL6sUTgEKCed .cluster-label text{fill:#333;}#mermaid-svg-TY3voL6sUTgEKCed .cluster-label span{color:#333;}#mermaid-svg-TY3voL6sUTgEKCed .label text,#mermaid-svg-TY3voL6sUTgEKCed span{fill:#333;color:#333;}#mermaid-svg-TY3voL6sUTgEKCed .node rect,#mermaid-svg-TY3voL6sUTgEKCed .node circle,#mermaid-svg-TY3voL6sUTgEKCed .node ellipse,#mermaid-svg-TY3voL6sUTgEKCed .node polygon,#mermaid-svg-TY3voL6sUTgEKCed .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-TY3voL6sUTgEKCed .node .label{text-align:center;}#mermaid-svg-TY3voL6sUTgEKCed .node.clickable{cursor:pointer;}#mermaid-svg-TY3voL6sUTgEKCed .arrowheadPath{fill:#333333;}#mermaid-svg-TY3voL6sUTgEKCed .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-TY3voL6sUTgEKCed .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-TY3voL6sUTgEKCed .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-TY3voL6sUTgEKCed .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-TY3voL6sUTgEKCed .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-TY3voL6sUTgEKCed .cluster text{fill:#333;}#mermaid-svg-TY3voL6sUTgEKCed .cluster span{color:#333;}#mermaid-svg-TY3voL6sUTgEKCed div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-TY3voL6sUTgEKCed :root{–mermaid-font-family:“trebuchet ms”,verdana,arial,sans-serif;} 创建 恢复 存储 原发器Originator 备忘录Memento 负责人Caretaker 核心原则: 封装保护:不暴露对象内部状态细节状态分离:将状态保存逻辑与业务逻辑解耦历史管理:支持多状态快照管理二、模式结构解析 2.1 UML类图 #mermaid-svg-2GzZ8BDvyzGiJ4QX {font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .error-icon{fill:#552222;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .marker{fill:#333333;stroke:#333333;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .marker.cross{stroke:#333333;}#mermaid-svg-2GzZ8BDvyzGiJ4QX svg{font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-2GzZ8BDvyzGiJ4QX g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-2GzZ8BDvyzGiJ4QX g.classGroup text .title{font-weight:bolder;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .nodeLabel,#mermaid-svg-2GzZ8BDvyzGiJ4QX .edgeLabel{color:#131300;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .label text{fill:#131300;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .classTitle{font-weight:bolder;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .node rect,#mermaid-svg-2GzZ8BDvyzGiJ4QX .node circle,#mermaid-svg-2GzZ8BDvyzGiJ4QX .node ellipse,#mermaid-svg-2GzZ8BDvyzGiJ4QX .node polygon,#mermaid-svg-2GzZ8BDvyzGiJ4QX .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX g.clickable{cursor:pointer;}#mermaid-svg-2GzZ8BDvyzGiJ4QX g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-2GzZ8BDvyzGiJ4QX g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .dashed-line{stroke-dasharray:3;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #compositionStart,#mermaid-svg-2GzZ8BDvyzGiJ4QX .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #compositionEnd,#mermaid-svg-2GzZ8BDvyzGiJ4QX .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #dependencyStart,#mermaid-svg-2GzZ8BDvyzGiJ4QX .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #dependencyStart,#mermaid-svg-2GzZ8BDvyzGiJ4QX .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #extensionStart,#mermaid-svg-2GzZ8BDvyzGiJ4QX .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #extensionEnd,#mermaid-svg-2GzZ8BDvyzGiJ4QX .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #aggregationStart,#mermaid-svg-2GzZ8BDvyzGiJ4QX .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX #aggregationEnd,#mermaid-svg-2GzZ8BDvyzGiJ4QX .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-2GzZ8BDvyzGiJ4QX .edgeTerminals{font-size:11px;}#mermaid-svg-2GzZ8BDvyzGiJ4QX :root{–mermaid-font-family:“trebuchet ms”,verdana,arial,sans-serif;} 创建和使用 存储 Originator -state: Object +createMemento() : Memento +restoreMemento(Memento) Memento -state: Object +getState() : Object +setState(Object) Caretaker -mementos: List +addMemento(Memento) +getMemento(int) : Memento 2.2 关键角色 角色职责示例Originator创建备忘录文本编辑器Memento存储状态编辑器快照Caretaker管理备忘录历史记录管理器三、代码实战:文本编辑器实现 3.1 场景描述 实现文本编辑器的核心功能: 文本内容编辑保存当前状态支持多次撤销/重做支持指定版本恢复3.2 核心实现 // 备忘录接口 public interface EditorMemento {// 空接口,用于类型标记 }// 文本备忘录 public class TextMemento implements EditorMemento {private final String content;private final long timestamp;public TextMemento(String content) {this.content = content;this.timestamp = System.currentTimeMillis();}public String getContent() {