/**
* 目标对象:将要被备忘的对象
*/
class Word {
private String content;
private String image;
private String table;
public Word(String content, String image, String table) {
super();
this.content = content;
this.image = image;
this.table = table;
}
public WordMemento memento(){
return new WordMemento(this);
}
public void recovery(WordMemento memento){
this.content = memento.getContent();
this.image = memento.getImage();
this.table = memento.getTable();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
}
}
/**
* 备忘录对象
*/
class WordMemento{
private String content;
private String image;
private String table;
public WordMemento(Word word) {
this.content = word.getContent();
this.image = word.getImage();
this.table = word.getTable();
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getTable() {
return table;
}
public void setTable(String table) {
this.table = table;
}
}
/**
* 负责人对象:负责记录备忘录对象
*/
class CareTaker{
private List<WordMemento> list = new ArrayList<>();
private int index = 0;
public void setMemento(WordMemento memento){
list.add(memento);
this.index = list.size();
}
public WordMemento getWordMemento(){
if(index == 0){
System.out.println("没有可还原的内容");
return null;
}
WordMemento memento = list.get(index-1);
list.remove(index-1);
index--;
return memento;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有