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

域名到期换个公司做网站沧州制作网站

域名到期换个公司做网站,沧州制作网站,智慧政务网站怎么做,做海外贸易的网站名叫什么状态模式 介绍 设计模式定义案例问题堆积在哪里解决办法状态模式一个对象 状态可以发生改变 不同的状态又有不同的行为逻辑游戏角色 加载不同的技能 每个技能有不同的#xff1a;攻击逻辑 攻击范围 动作等等1 状态很多 2 每个状态有自己的属性和逻辑每种状态单独写一个类 角色…状态模式 介绍 设计模式定义案例问题堆积在哪里解决办法状态模式一个对象 状态可以发生改变 不同的状态又有不同的行为逻辑游戏角色 加载不同的技能 每个技能有不同的攻击逻辑 攻击范围 动作等等1 状态很多 2 每个状态有自己的属性和逻辑每种状态单独写一个类 角色需要那个状态就加载哪一个 类图 角色  stateBase 抽象状态 stateA 具体状态A stateB 具体状态B stateC 具体状态C FactoryState  状态工厂 代码 RoleContext using System.Collections; using System.Collections.Generic; using UnityEngine;public class RoleContext {string name;StateBase currentState null;public RoleContext(){name 独孤求败;}// 展示动作public void ShowAction(){if (null ! currentState){currentState.Action();}}// 切换状态public void ChangeActionState(StateBase newState){currentState newState;} }StateBase public abstract class StateBase {public abstract void Action(); }StateA  using System.Collections; using System.Collections.Generic; using UnityEngine;public class StateA : StateBase {string name 普攻;public override void Action(){Debug.Log(释放- name);} }StateB  using System.Collections; using System.Collections.Generic; using UnityEngine;public class StateB : StateBase {string name 次元斩;public override void Action(){Debug.Log(释放- name);} }StateC using System.Collections; using System.Collections.Generic; using UnityEngine;public class StateC:StateBase {string name 升龙击;public override void Action(){Debug.Log(释放- name);} }FactoryState using System.Collections; using System.Collections.Generic; using UnityEngine;public class FactoryState {// 单例static FactoryState self null;FactoryState() { }public static FactoryState Instance(){if (null self)self new FactoryState();return self;}Dictionarystring, StateBase dic new Dictionarystring, StateBase();// 获取实例public StateBase GetStateIns(string className){StateBase ins null;switch (className){case StateA:{if (false dic.ContainsKey(className))ins new StateA();elseins dic[className];}break;case StateB:{if (false dic.ContainsKey(className))ins new StateB();elseins dic[className];}break;case StateC:{if (false dic.ContainsKey(className))ins new StateC();elseins dic[className];}break;default:Debug.Log(未发现该类);break;}return ins;} }测试代码 using System.Collections; using System.Collections.Generic; using UnityEngine;public class TestZT : MonoBehaviour {void Start(){RoleContext role new RoleContext();// 切换技能Arole.ChangeActionState(FactoryState.Instance().GetStateIns(StateA));role.ShowAction();// 切换技能Brole.ChangeActionState(FactoryState.Instance().GetStateIns(StateB));role.ShowAction();// 切换技能Crole.ChangeActionState(FactoryState.Instance().GetStateIns(StateC));role.ShowAction();}}结果 总结 状态模式 1 是一个非常好用的 解耦合的手段 角色不同的状态封装不同的动作属性限制 2 非常符合对修改封闭对扩展开发的原则。 3 让状态的职责更加的单一 4 也符合了依赖倒置 依赖了抽象 5 符合了迪米特原则角色对状态类内部的具体实现不知道
http://www.dnsts.com.cn/news/213156.html

相关文章:

  • yy头像在线制作网站网站开发的经济可行性
  • django网站开发实例韩城建设公司网站
  • 票务网站做酒店推荐的目的个人建站什么网站好
  • 北京网站优化对策网站开发培训排名
  • 帮别人设计网站的网站深圳住房与城乡建设部网站
  • 网站做成软件关键词排名seo
  • 四川旅游seo整站优化站优化搜索引擎整合营销
  • 什么网站权重高html网站设计模板下载
  • 岳阳市住房和城乡建设局网站网页游戏新游戏
  • 怎么做网站投放广告的代理商广州市企业网站建设怎么样
  • 电力建设期刊网站经常维护吗那个网站可以做全景图
  • 网站底部优化文字ui培训哪好
  • 潍坊建设网站最近重大新闻头条
  • 邯山区建设局网站wordpress 模板 源码
  • 动态表单的设计与实现郑州抖音seo推广
  • 天天向上做图网站成安专业做网站
  • 手机网站开发用什么框架好专业的外贸网站建设公司价格
  • 建设网站能盈利吗适合博客的wordpress主题
  • 我的电脑做网站服务器怎么在建筑网站做翻译兼职
  • 网站头部修改宠物网站模板
  • 企业门户网站建设 北京宁波网站建设yiso
  • 湛江市住房和城乡建设局网站学校培训
  • 咸宁市网站建设珠海自助建站软件
  • 移动端网站设计尺寸企业为什么融资
  • 一站式手机网站制作甘肃兰州地震最新消息刚刚
  • 网站生成手机端wordpress 用什么服务器配置
  • 上海建站费用贵阳网站开发多少钱
  • 网站中的二级菜单怎么做23成都电子商城网站开发
  • 章丘市建设局网站百度指数与百度搜索量
  • windows7怎么做网站服务器vpn免流网站建设