状态设计模式
来源:互联网 发布:平面设计需要的软件 编辑:程序博客网 时间:2024/06/05 16:52
场景:红绿灯
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WCF_Binding{ public class Context { public IState State { get; set; } public Context(IState state) { State = state; } public void Request() { State.Handler(this); } } public interface IState { void Handler(Context context); } public class RedState : IState { public void Handler(Context context) { Console.WriteLine("红灯停"); context.State = new YellowState(); } } public class YellowState : IState { public void Handler(Context context) { Console.WriteLine("黄灯"); context.State = new GreenState(); } } public class GreenState : IState { public void Handler(Context context) { Console.WriteLine("绿灯行"); context.State = new RedState(); } } public class StateTest { public static void StateMain() { Context context = new Context(new RedState()); int i=1; do { context.Request(); i++; } while (i <= 6); Console.ReadLine(); } }}
0 0
- 设计模式:状态模式
- 设计模式-----状态模式
- 设计模式 状态模式
- 设计模式 - 状态模式
- 设计模式---状态模式
- 设计模式-状态模式
- 设计模式:状态模式
- 设计模式 - 状态模式
- 设计模式-状态模式
- 设计模式--状态模式
- 设计模式-状态模式
- 设计模式:状态模式
- 设计模式-状态模式
- 设计模式-状态模式
- [设计模式]状态模式
- 设计模式 状态模式
- 设计模式--状态模式
- 设计模式--状态模式
- Be cautious when using Map and Set in Java
- iOS 简单的猜颜色游戏 界面设计的比较简单 - -
- iOS 文件操作
- 从300到300万,一个远程外包团队的发展历程和经验
- JAVA面试题集(上)
- 状态设计模式
- 短信接收
- NY 题目6 喷水装置(一)(贪心问题)
- markdown编辑器快速入门
- C# Stopwatch 类
- python 循环
- 如何定义变长的TLV结构体?
- Struts2.3.1升级到Struts2.3.24相关问题
- mysql之Truncate 和Delete语句删除表的所有记录