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

晋江网站建设qzdzi网店运营怎么学

晋江网站建设qzdzi,网店运营怎么学,阿里云做网站电话,南京网站优樱化文章目录 Java 设计模式之备忘录模式概述UML代码实现 Java 设计模式之备忘录模式 概述 备忘录(Memento):在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。方便对该对象恢复到原先保存的状态。 UML Originnato…

文章目录

  • Java 设计模式之备忘录模式
    • 概述
    • UML
    • 代码实现

Java 设计模式之备忘录模式

概述

  • 备忘录(Memento):在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。方便对该对象恢复到原先保存的状态。

UML

在这里插入图片描述

  • Originnator:发起者类,指需要被保存状态的对象,负责创建备忘录并恢复状态。
  • Memento:备忘录类,负责存储发起者的内部状态。
  • Caretaker:管理者类,负责保存和管理备忘录,不直接操作备忘录的内容。

代码实现

定义发起者类:

public class TextEditor {private String content;public String getContent() {return content;}public void setContent(String content) {this.content = content;}// 创建备忘录public TextEditorMemento createMemento() {return new TextEditorMemento(content);}// 恢复备忘录public void restoreMemento(TextEditorMemento memento) {this.content = memento.getContent();}@Overridepublic String toString() {return "TextEditor{" +"content='" + content + '\'' +'}';}
}

定义备忘录类:

public class TextEditorMemento {private final String content;public TextEditorMemento(String content) {this.content = content;}public String getContent() {return content;}
}

定义管理类:

public class TextEditorHistory {private final Stack<TextEditorMemento> history = new Stack<>();// 保存状态public void save(TextEditor editor) {history.push(editor.createMemento());}// 撤销操作public void undo(TextEditor editor) {if (!history.isEmpty()) {editor.restoreMemento(history.pop());} else {System.out.println("没有历史数据,不能撤销");}}
}

使用:

public class Client {public static void main(String[] args) {TextEditorHistory history = new TextEditorHistory();TextEditor editor = new TextEditor();// 编辑内容并保存状态editor.setContent("one");history.save(editor);System.out.println(editor);// 编辑内容并保存状态editor.setContent("two");history.save(editor);System.out.println(editor);// 只编辑内容editor.setContent("three");// 第1次撤销操作history.undo(editor);System.out.println("第1次撤销操作后:" + editor);// 第2次撤销操作history.undo(editor);System.out.println("第2次撤销操作后:" + editor);// 第3次撤销操作history.undo(editor);System.out.println("第3次撤销操作后:" + editor);}
}

输出:

TextEditor{content='one'}
TextEditor{content='two'}
第1次撤销操作后:TextEditor{content='two'}
第2次撤销操作后:TextEditor{content='one'}
没有历史数据,不能撤销
第3次撤销操作后:TextEditor{content='one'}

文章转载自:

http://IcBE6oWO.frghq.cn
http://KFrNuzt2.frghq.cn
http://UsRs9vgE.frghq.cn
http://5tgBrCtS.frghq.cn
http://C6kURBAY.frghq.cn
http://7yBD9SzS.frghq.cn
http://YJDV3ux3.frghq.cn
http://iD66XYrt.frghq.cn
http://UyfzjP2N.frghq.cn
http://o2R4qXl9.frghq.cn
http://qhsZTehT.frghq.cn
http://ONoJ3hO7.frghq.cn
http://QwKRDpzK.frghq.cn
http://a3WK0roJ.frghq.cn
http://2a8SomRj.frghq.cn
http://luyI4poj.frghq.cn
http://qzFBWm7x.frghq.cn
http://PTLXeJ9M.frghq.cn
http://bwP8Lef8.frghq.cn
http://o6CJ0pig.frghq.cn
http://rZ5FdX0v.frghq.cn
http://rv8q66gv.frghq.cn
http://12ZeXm5R.frghq.cn
http://kwQrVcqv.frghq.cn
http://qIkvcxFF.frghq.cn
http://0KrbRyHZ.frghq.cn
http://uD76eGfx.frghq.cn
http://cs3E1E91.frghq.cn
http://oD5h4unu.frghq.cn
http://dlvCR8pp.frghq.cn
http://www.dtcms.com/wzjs/655897.html

相关文章:

  • 关于网站建设请示35网站建设
  • 一个网站开发项目小组成员easywechat wordpress
  • 免费做简单网站国内人做韩国网站一般都卖什么手续
  • 珠海网站seo找产品代理加盟
  • 微站小程序购物网站html
  • 做手机网站要多少钱国外修图教程网站
  • 站长工具seo综合查询方法河南省建筑业协会官网
  • 给网站写文章怎么做的如何自学网站建设书籍
  • 销售网站的优秀标准漕泾网站建设
  • 文山住房和城乡建设局网站腾讯短网址在线生成
  • iis默认网站建设中电子书网站开发
  • 响应式网站建设公司'wordpress skype
  • 网站建设服务费应该算什么科目网站上的公告怎么做参考文献
  • 响应式网站div居中简单个人网页设计html
  • 网站开发大致需要哪些步骤益阳市住房和城乡建设局网站
  • 旅游网站制作方案嵌入式软件开发做什么
  • 旅游网站开发网站设计报告书巴顿品牌设计
  • 网站的不同类建设网站怎么入账
  • 手机网站淘宝客营销方案论文
  • 唐河企业网站制作怎么样怎么用ps做网站首页
  • 北京住房与城乡建设厅网站首页miya1173跳转接口
  • 企业网站推广平台微信建网站服务
  • 遵义怎样做网站wordpress 后台 主题
  • 集团网站建设招标附近做广告牌的电话
  • 怎样做网站漂浮扬州做网站的
  • 杭州做网站hzyze深圳外贸建站网络推广哪家好
  • 网站列表怎么做东莞什么行业做网站的多
  • 无锡做网站公司哪家比较好python网站开发教程
  • 优秀设计师的个人网站买卖网站
  • 中山做网站网站建设备案条件