Alamps学习设计模式之备忘录模式(笑话:劫个色OR抢个鸡蛋版)
//设计模式之备忘录模式(月光宝盒版),只要喊菠萝菠萝蜜,就能返回事件的原点。//至尊宝//爱你一万年
class LoverWords {// 模拟Memento
private String words;
public LoverWords(String words) {
super();
this.words = words;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
}
//月光宝盒
class YueGuangBaOHe {// 模拟Caretaker 守护者
class LoverWords {// 模拟Memento
private String words;
public LoverWords(String words) {
super();
this.words = words;
}
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
}
//月光宝盒
class YueGuangBaOHe {// 模拟Caretaker 守护者
LoverWords words;
public LoverWords getWords() {
return words;
}
public void setWords(LoverWords words) {
this.words = words;
}
}
class ZJB {// //至尊宝//模拟Originator
private String words;
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public LoverWords SayLoverWords() {
return new LoverWords(words);
}
public void SaveWhatIhaveSaied(LoverWords loverwords)
{
this.words = loverwords.getWords();
}
public void Show()
{
System.out.println("对话:"+words);
}
}
public class CopyOfYGBHDemoXXX {
public static void main(String[] args) {
ZJB zjb = new ZJB();
zjb.setWords("姑娘,抢个鸡蛋");
zjb.Show();
YueGuangBaOHe ygbh = new YueGuangBaOHe();
ygbh.setWords(zjb.SayLoverWords());////月光宝盒记录 (保存)至尊宝以前说过的话
zjb.setWords("姑娘,劫个色吧!");
zjb.Show();
System.out.println("旁白:劫个色呢,多大个事,我以为抢鸡蛋呢!");
//至尊宝,后悔了,收回刚才说的那一句、
System.out.println("旁白:至尊宝,后悔了,收回刚才说的那一句");
zjb.SaveWhatIhaveSaied(ygbh.getWords());
zjb.Show();
}
}
-------------测试------------
对话:姑娘,抢个鸡蛋
对话:姑娘,劫个色吧!
旁白:劫个色呢,多大个事,我以为抢鸡蛋呢!
旁白:至尊宝,后悔了,收回刚才说的那一句
对话:姑娘,抢个鸡蛋
public LoverWords getWords() {
return words;
}
public void setWords(LoverWords words) {
this.words = words;
}
}
class ZJB {// //至尊宝//模拟Originator
private String words;
public String getWords() {
return words;
}
public void setWords(String words) {
this.words = words;
}
public LoverWords SayLoverWords() {
return new LoverWords(words);
}
public void SaveWhatIhaveSaied(LoverWords loverwords)
{
this.words = loverwords.getWords();
}
public void Show()
{
System.out.println("对话:"+words);
}
}
public class CopyOfYGBHDemoXXX {
public static void main(String[] args) {
ZJB zjb = new ZJB();
zjb.setWords("姑娘,抢个鸡蛋");
zjb.Show();
YueGuangBaOHe ygbh = new YueGuangBaOHe();
ygbh.setWords(zjb.SayLoverWords());////月光宝盒记录 (保存)至尊宝以前说过的话
zjb.setWords("姑娘,劫个色吧!");
zjb.Show();
System.out.println("旁白:劫个色呢,多大个事,我以为抢鸡蛋呢!");
//至尊宝,后悔了,收回刚才说的那一句、
System.out.println("旁白:至尊宝,后悔了,收回刚才说的那一句");
zjb.SaveWhatIhaveSaied(ygbh.getWords());
zjb.Show();
}
}
-------------测试------------
对话:姑娘,抢个鸡蛋
对话:姑娘,劫个色吧!
旁白:劫个色呢,多大个事,我以为抢鸡蛋呢!
旁白:至尊宝,后悔了,收回刚才说的那一句
对话:姑娘,抢个鸡蛋