星空网 > 软件开发 > ASP.net

MementoPattern(备忘录模式)

/** * 备忘录模式 * @author TMAC-J * 用于存储bean的状态 */public class MementoPattern {    public class Memento{        private int lifeValue;        private int grade;    public int getLifeValue() {      return lifeValue;    }    public void setLifeValue(int lifeValue) {      this.lifeValue = lifeValue;    }    public int getGrade() {      return grade;    }    public void setGrade(int grade) {      this.grade = grade;    }      }    public class Originator{        public Originator(int lifeValue,int grade) {      this.grade = grade;      this.lifeValue = lifeValue;    }        private int lifeValue;        private int grade;    public int getLifeValue() {      return lifeValue;    }    public void setLifeValue(int lifeValue) {      this.lifeValue = lifeValue;    }    public int getGrade() {      return grade;    }    public void setGrade(int grade) {      this.grade = grade;    }        public Memento createMemento(){      Memento memento = new Memento();      memento.setGrade(this.grade);      memento.setLifeValue(this.lifeValue);      return memento;    }        public void setMemento(Memento memento){      this.lifeValue = memento.getLifeValue();      this.grade = memento.getGrade();    }      }    public class MementoManage{        private Memento memento;    public Memento getMemento() {      return memento;    }    public void setMemento(Memento memento) {      this.memento = memento;    }      }    public void test(){    Originator originator = new Originator(10,10);    Memento memento = originator.createMemento();    originator.setMemento(memento);  }  }

 




原标题:MementoPattern(备忘录模式)

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

BIC:https://www.ikjzd.com/w/1573153302557138945
必创汇:https://www.ikjzd.com/w/1573153309033144322
Bidadoo:https://www.ikjzd.com/w/1573153309717159937
BigBigAds(头条广告情报):https://www.ikjzd.com/w/1573153316306067457
Bigcartel:https://www.ikjzd.com/w/1573153317560508418
BigSpy:https://www.ikjzd.com/w/1573153321146294274
秦皇岛到丹东旅游景点大全 秦皇岛到丹东开车多长时间:https://www.vstour.cn/a/408253.html
求推荐适合情侣玩的地方,三天时间,谢谢:https://www.vstour.cn/a/408254.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流