- 浏览: 602347 次
- 性别:
- 来自: 卡哇伊
文章分类
- 全部博客 (299)
- C# (25)
- Java (1)
- WinForm (0)
- Asp.Net (86)
- Jsp (2)
- Php (1)
- Web Service (0)
- Desgin Patterns (19)
- Data Structure & Algorithms (1)
- SQLserver (41)
- Mysql (0)
- Oracle (2)
- Javascript (50)
- Ajax (10)
- Jquery (1)
- Flex (0)
- Regular Expression (5)
- DIV+CSS+XHTML+XML (18)
- Software Test (0)
- Linux (0)
- Utility (17)
- Net Digest (4)
- windows 2003 (10)
- Other (4)
- English (1)
- IT Term (1)
最新评论
-
w497480098h:
学习了 很好谢谢
SQL Server下无限多级别分类查询解决办法(简单查询树形结构数据库表) -
main_fun:
确实不错
iframe自适应高度 -
jveqi:
...
DBA -
mxcie:
其它版本没有确认,今天使用vs2003时,其.sln文件也需要 ...
彻底删除项目的VSS源代码管理信息 -
moneyprosper:
就只有IE支持,火狐和谷歌都不支持此种方法。正在寻找中。。。
从父页面读取和操作iframe中内容方法
意图
在不破坏封装性的前提下,捕获一个对象内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态.
适用性
必须保存一个对象在某一个时刻的(部分)状态,这样以后需要时它才能恢复到先前的状态.
构成:
1.备忘录(Memento)角色:保持原发器(Originator)的内部状态,根据原发器来决定保存哪些内部的状态.(备忘录角色就好比是一个日记本把当前发生的一些事情记录下来,当过段时间回过头来再看日记本的时候就知道在那个时刻发生了什么事情)
备忘录可以有效地利用两个接口.看管者只能调用狭窄(功能有限)的接口---它只能传递备忘录给其他对象.而原发器可以调用一个宽阔(功能强大)的接口,通过这个接口可以访问所有需要的数据,使原发器可以返回先前的状态.
2.原发器(Originator)角色:创建一个备忘录,记录它当前内部状态.可以利用一个备忘录来回复它的内部状态.
3.看管者(Caretaker)角色:只负责看管备忘录.不可以对备忘录的内容操作或检查.
ClassDiagram:
SequenceDiagram:
//公司销售记录示例 class Client { static void Main(string[] args) { Originator ori = new Originator("张三", "123456", 1000); ori.Show(); Caretaker caretaker = new Caretaker(); //保存备忘录 caretaker.Memento = ori.SaveMemento(); ori = new Originator("李四", "654321", 2000); ori.Show(); //恢复备忘录 ori.RestoreMemento(caretaker.Memento); ori.Show(); Console.ReadKey(); } } /// <summary> /// 备忘录角色 /// </summary> class Memento { private string name; private string phone; private double budget; public Memento(string name, string phone, double budget) { this.name = name; this.phone = phone; this.budget = budget; } public string Name { get { return name; } set { name = value; } } public string Phone { get { return phone; } set { phone = value; } } public double Budget { get { return budget; } set { budget = value; } } } /// <summary> /// 原发器角色 /// </summary> class Originator { private string name; private string phone; private double budget; public Originator(string name, string phone, double budget) { this.name = name; this.phone = phone; this.budget = budget; } public string Name { get { return name; } set { name = value; } } public string Phone { get { return phone; } set { phone = value; } } public double Budget { get { return budget; } set { budget = value; } } //保存备忘录 public Memento SaveMemento() { return new Memento(name, phone, budget); } //恢复备忘录 public void RestoreMemento(Memento memento) { name = memento.Name; phone = memento.Phone; budget = memento.Budget; } public void Show() { Console.WriteLine("销售期望"); Console.WriteLine("姓名: {0}", name); Console.WriteLine("电话: {0}", phone); Console.WriteLine("预算: {0}", budget); } } /// <summary> /// 看管者 /// </summary> class Caretaker { private Memento memento; internal Memento Memento { get { return memento; } set { memento = value; } } }
发表评论
-
AbstractFactoryPattern(二)
2009-05-01 21:42 679关于抽象工厂(Abstract F ... -
VisitorPattern
2009-05-01 19:20 807意图表示一个作用于某 ... -
MediatorPattern
2009-05-01 11:16 691意图用一个中介对象封装一系列的对象交互.中介者使各对象不需要显 ... -
Statepattern
2009-04-30 13:45 766意图允许一个对象在其 ... -
Chain of Responsibility Pattern
2009-04-28 23:23 837意图使多个对象都有机会处理请求,从而避免请求的发送者和接收者之 ... -
InterpreterPattern
2009-04-28 14:43 830意图给定一个语言之后,解释器模式可以定义出其文法的一种表示,并 ... -
IteratorPattern
2009-04-26 18:15 795意图提供一种方法顺序 ... -
CommandPattern
2009-04-26 13:35 673意图:将一个请求封装为 ... -
StrategyPattern
2009-04-25 19:08 717策略模式(Strategy Pattern) 中体现了两个非常 ... -
TemplateMethodPattern
2009-04-25 13:24 810TemplateMethodPattern:定义一个操作中算法 ... -
PrototypePattern
2009-04-23 15:46 771意图用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的 ... -
追MM与23种设计模式
2009-04-21 15:13 6701、FACTORY—追MM少不了请 ... -
AbstractFactoryPattern
2009-04-21 13:23 721意图 提供一个创建一系列相关或相互依赖对象的接口,而无需指定 ... -
FactoryMethodPattern
2009-04-19 22:20 835工厂方法(FactoryMethod ... -
ObserverPattern
2009-03-27 17:40 771观察者模式又叫做发布- ... -
SimpleFactoryPattern
2009-03-26 00:57 770工厂模式专门负责将大量有共同接口的类实例化。工厂模式可以动态决 ... -
Builder Pattern
2009-03-21 18:47 1380建造者(Builder)模式 ... -
Singleton Pattern
2009-03-16 16:50 961单件模式:(Singleton pattern) 1.目的 1 ...
相关推荐
在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样以后就可将该对象恢复到保存的状态。
本文以一个简单实例讲述了C#备忘录模式(Memento Pattern)的实现方法。分享给大家供大家参考。具体实现方法如下: 简单来说,备忘录模式就是支持回退操作。假设让一个Notepad支持回退操作,如何实现呢? 首先需要一个...
为了使软件的使用更加人性化,对于误操作,我们需要提供一种类似“后悔药”的机制,让软件系统可以回到误操作前的状态,因此需要保存用户每一次操作时系统的状态,一旦出现误操作,可以把存储的历史状态取出即可回到...
备忘录模式(Memento Pattern) 策略模式(Strategy Pattern) 抽象工厂模式(Abstract Factory Pattern) 代理模式(Proxy Pattern) 单例模式(Singleton Pattern) 迭代器模式(Iterator Pattern) 访问者模式(Visitor ...
创建型: 1. 单件模式(Singleton Pattern) 2. 抽象工厂(Abstract Factory) 3.... 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式(State Pattern)
创建型: 1. 单件模式(Singleton Pattern) 2. 抽象工厂(Abstract Factory) ... 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式(State Pattern)
C#设计模式(23种设计模式) 1. 单件模式(Singleton Pattern) ...20. 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式(State Pattern)
创建型: 1. 单件模式(Singleton Pattern) ... 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式(State Pattern) @Author kwming
备忘录模式(Memento Pattern) 观察者模式(Observer Pattern) 状态模式(State Pattern) 空对象模式(Null Object Pattern) 策略模式(Strategy Pattern) 模板模式(Template Pattern) 访问者模式...
备忘录模式(Memento Pattern) 观察者模式(Observer Pattern) 状态模式(State Pattern) 策略模式(Strategy Pattern) 模板方法模式(Template Method Pattern) 访问者模式(Visitor ...
C# 32种设计模式: 创建型: 1. 单件模式(Singleton ... 备忘录模式(Memento Pattern) 21. 策略模式(Strategy Pattern) 22. 访问者模式(Visitor Pattern) 23. 状态模式(State Pattern)
备忘录模式(Memento Pattern) 观察者模式(Observer Pattern) 状态模式(State Pattern) 空对象模式(Null Object Pattern) 策略模式(Strategy Pattern) 模板模式(Template Pattern) 访问者模式(Visitor ...
│ └─MementoPattern │ ├─bin │ │ └─Debug │ ├─obj │ │ └─Debug │ │ └─TempPE │ └─Properties ├─19.MediatorPattern │ ├─html │ └─MediatorPattern │ ├─bin │ │ └─Debug │ ...
AbstractFactoryPattern AdapterPattern IBridgePattern ...MementoPattern ObserverPattern PrototypePattern ProxyPattern SingletonPattern StatePattern StrategyPattern TemplatePattern VisitorPattern
协调多个对象之间的交互——中介者模式(三) 协调多个对象之间的交互——中介者模式(四) 协调多个对象之间的交互——中介者模式(五) 备忘录模式-Memento Pattern 撤销功能的实现——备忘录模式(一) 撤销功能...
The Swift programming... The Memento Pattern Chapter 24. The Strategy Pattern Chapter 25. The Visitor Pattern Chapter 26. The Template Method Pattern Part 5 - The MVC Pattern Chapter 27. The MVC Pattern
5. [备忘录模式](worthed/OriginBlog/blob/master/articles/MementoPattern.md) 6. [迭代器模式](worthed/OriginBlog/blob/master/articles/IteratorPattern.md) 7. [命令模式](worthed/OriginBlog/blob/master/...
Java design patterns with the Simplest real world examples which are easy to understand & remember as well. Table of Contents PREFACE ABOUT DESIGN PATTERNS SINGLETON PATTERN ...MEMENTO PATTERN