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

增城做网站wordpress默认登录页面

增城做网站,wordpress默认登录页面,百度智能云网站建设,怎样提高网站打开速度慢设计模式之备忘录模式 Memento Pattern V1.0核心概念角色代码示例程序运行结果代码讲解 适用场景 V1.0 核心概念 备忘录模式的核心是定义一个备忘录类(Memento),这个类的实例能够表示发起人类(Originator)的一种状态…

设计模式之备忘录模式 Memento Pattern

    • V1.0
    • 核心概念
    • 角色
    • 代码示例
      • 程序运行结果
      • 代码讲解
    • 适用场景

V1.0

核心概念

备忘录模式的核心是定义一个备忘录类(Memento),这个类的实例能够表示发起人类(Originator)的一种状态。发起人类提供生成备忘录对象的接口,以保存其当时的状态,也提供了接口传入备忘录实例,能够使用备忘录对象实例中保存的信息恢复其保存时的状态。

角色

  • 发起人(Originator):具体的业务类,提供生成备忘录的接口,也提供使用备忘录对象来恢复状态的接口。
  • 备忘录(Memento):由发起人根据其状态创建,保存了发起人创建时的状态信息,之后可以用来恢复发起人的状态。
  • 管理者(Caretaker):用于保存备忘录对象,以及在向其查询时提供备忘录对象。

代码示例

using System;
using System.ComponentModel;public class Originator
{private string _state = null;public string state{get => _state;set => _state = value;}public Memento createMemento(){return new Memento(state);}public void setState(string state){this.state = state;}public void recoverFromMemento(Memento m){state = m.state;Console.WriteLine($"The state of the originator is restored to '{state}'");}public void displayState(){Console.WriteLine($"The state of the originator now: {state}");}
};public class Memento
{private string _state;public string state{get => _state;set => _state = value;}public Memento(string state){this.state = state;}};public class Caretaker
{private List<Memento> list = new();public void addMemento(Memento m){list.Add(m);}public Memento getMemento(int index){return list.Count > index ? list[index] : null;}
}public class Program
{public static void Main(string[] arg){//创建发起人和管理者Originator o = new();Caretaker ct = new();//设置发起人的状态,展示并保存为Memento对象到管理者o.setState("Idle");o.displayState();ct.addMemento(o.createMemento());//设置发起人的状态,展示并保存为Memento对象到管理者o.setState("Working");o.displayState();ct.addMemento(o.createMemento());//设置发起人的状态,展示并保存为Memento对象到管理者o.setState("Stop");o.displayState();ct.addMemento(o.createMemento());//恢复Originator的状态到Idle状态o.recoverFromMemento(ct.getMemento(0));o.displayState();//恢复Originator的状态到Working状态o.recoverFromMemento(ct.getMemento(1));o.displayState();}
}

程序运行结果

The state of the originator now: Idle
The state of the originator now: Working
The state of the originator now: Stop
The state of the originator is restored to 'Idle'
The state of the originator now: Idle
The state of the originator is restored to 'Working'
The state of the originator now: Working

代码讲解

  • Originator类
    在这段代码中,Originator类的state属性是Originator类的状态,Originator类也提供了创建备忘录对象的createMemento方法,从备忘录对象中恢复状态的recoverFromMemento方法,以及展示Originator类当前状态的方法displayState。

  • Memento类
    Memento类中的state属性用来保存对应的Originator的状态,在Originator恢复状态时要用到。

  • Caretaker类
    Caretaker类定义了private访问权限的list列表,用于保存Memento对象,提供了addMemento方法用来向list列表中新增Memento对象,以及getMemento方法用于从list列表中获取指定序号的Memento对象。

  • Program类
    Main函数中创建了发起人和管理者,变更发起人的状态,以及展示并保存Memento对象,之后从管理者中获取Memento对象,以恢复发起人的状态。

适用场景

备忘录模式可以用来保存快照的场景中,例如程序或者虚拟机的快照。
备忘录模式也可以用在撤销或恢复状态的场景中,通过保存当前的状态,在撤消操作时可以使用备忘录对象恢复之前的状态。


文章转载自:

http://AlgC6okL.mjtft.cn
http://5t7H08kJ.mjtft.cn
http://Jh237l9z.mjtft.cn
http://Ges7TLAB.mjtft.cn
http://0yHsk5GU.mjtft.cn
http://jU2ATtf8.mjtft.cn
http://9xKNsWsK.mjtft.cn
http://O5rptqIG.mjtft.cn
http://TvL5Z45N.mjtft.cn
http://iaWI9JIT.mjtft.cn
http://HL2woXBU.mjtft.cn
http://sdLmJJCK.mjtft.cn
http://kryUcnCL.mjtft.cn
http://d71sxfu7.mjtft.cn
http://dYbXXPfE.mjtft.cn
http://nw2AdT0E.mjtft.cn
http://pdBrq1FO.mjtft.cn
http://opJVxVKK.mjtft.cn
http://6cchfWyw.mjtft.cn
http://3kFxGr7T.mjtft.cn
http://LF00LZGS.mjtft.cn
http://jGmdpxFP.mjtft.cn
http://c1g7M6Ie.mjtft.cn
http://totT6rAX.mjtft.cn
http://Bhq67KSn.mjtft.cn
http://ma4ivBLu.mjtft.cn
http://rlreHj0i.mjtft.cn
http://Ynauhgj9.mjtft.cn
http://z6KOosjC.mjtft.cn
http://mUN8oifL.mjtft.cn
http://www.dtcms.com/wzjs/701883.html

相关文章:

  • 网站背景更换建设品牌公司网站
  • 中国建设银行网站登陆大厂做网站
  • 重庆市网站备案网页设计学校官网代码
  • 济南济南网站建设网站建设无锡做网页
  • 网站推广的8种方法windows优化软件排行
  • 老牌网站建设青海省高等级公路建设管局网站
  • 昆明网站建设一条龙手机回收网站做多久
  • 淘宝联盟自建网站教程福州网站建设H5
  • 怎样建设电影网站开封网站制作
  • 菏泽定制网站建设推广小程序开发公司如何寻找客户
  • 如何做网站平台关注长春做网站seo
  • 商城网站备案要求常德市做网站的公司
  • 班级网站建设图片长沙手机网站建设公司哪家好
  • 南通e站网站建设wordpress后台打开慢
  • 网站制作教程谁的好好听的网络公司名称
  • 免费微信引流推广的方法一分钟看懂seo
  • 怎样推广网站自己制作app的应用程序
  • 常用的做网站的工具都有哪些做网站 php python
  • 有域名后如何建网站取消Wordpress外链转内链
  • 云南凡科建站网站改版总结
  • 有什么网站做的比较高大上工商注册公司名称核准
  • 太原手机网站设计免费申请空间的地址有哪些
  • 招远市建设局网站wordpress主体
  • 咸阳做网站xymokj中英文网站怎么做
  • 网站设计销售营销系统网站源码
  • 高端网站登录入口网络的推广
  • 广东网站建设公海康打开网站显示建设中
  • 开发一整个网站要多久wordpress 普通文本 quot
  • 网站先做移动站在做pc站可行吗网站建设对旅游意义
  • 网站开发公司怎么查网站推广有哪些举措