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

专业做汽车的网站北京微网站建设

专业做汽车的网站,北京微网站建设,如何在百度上投放广告,卓手机建网站Unity实现设计模式——模板方法模式 模板模式(Template Pattern)#xff0c; 指在一个抽象类公开定义了执行它的方法的模板。它的子类可以按需要重写方法实现#xff0c;但调用将以抽象类中定义的方式进行。 简单说#xff0c; 模板方法模式定义一个操作中的算法的骨架 指在一个抽象类公开定义了执行它的方法的模板。它的子类可以按需要重写方法实现但调用将以抽象类中定义的方式进行。 简单说 模板方法模式定义一个操作中的算法的骨架而将这些步骤延迟到子类中使得子类可以不改变一个算法的结构就可以重定义该算法的某些特定步骤。 注意模板方法模式和策略模式的区别 模板模式注意强调了抽象类公开定义了一个执行的模板方法而策略模式是对单个算法的封装更具有独立性 下面使用两个例子去介绍模板方法模式 1.第一个例子使用比较抽象的例子 一AbstractClass abstract class AbstractClass {public abstract void PrimitiveOperation1();public abstract void PrimitiveOperation2();// The Template methodpublic void TemplateMethod(){PrimitiveOperation1();PrimitiveOperation2();Debug.Log();} }二ConcreteClassA class ConcreteClassA : AbstractClass {public override void PrimitiveOperation1(){Debug.Log(ConcreteClassA.PrimitiveOperation1());}public override void PrimitiveOperation2(){Debug.Log(ConcreteClassA.PrimitiveOperation2());} }三ConcreteClassB class ConcreteClassB : AbstractClass {public override void PrimitiveOperation1(){Debug.Log(ConcreteClassB.PrimitiveOperation1());}public override void PrimitiveOperation2(){Debug.Log(ConcreteClassB.PrimitiveOperation2());} }四测试 public class TemplateMethodStructure : MonoBehaviour {void Start ( ){AbstractClass aA new ConcreteClassA();aA.TemplateMethod();AbstractClass aB new ConcreteClassB();aB.TemplateMethod();} }2.第二个例子使用一个三明治的制作过程来介绍 一Hoagie 三明治抽象基类 public abstract class Hoagie{public void MakeSandwich(){Debug.Log(Making new Sandwich);CutBun();if (CustomerWantsMeat()){AddMeat();}if (CustomerWantsCheese()){AddCheese();}if (CustomerWantsVegetables()){AddVegetables();}if (CustomerWantsCondiments()){AddCondiments();}WrapTheHoagie();}protected abstract void AddMeat();protected abstract void AddCheese();protected abstract void AddVegetables();protected abstract void AddCondiments();protected virtual bool CustomerWantsMeat() { return true; } // called Hookprotected virtual bool CustomerWantsCheese() { return true; }protected virtual bool CustomerWantsVegetables() { return true; }protected virtual bool CustomerWantsCondiments() { return true; }protected void CutBun(){Debug.Log(Bun is Cut);}protected void WrapTheHoagie(){Debug.Log(Hoagie is wrapped.);}}二ItalienHoagie 法式三明治 public class ItalienHoagie : Hoagie{protected override void AddMeat(){Debug.Log(Adding the Meat: Salami);}protected override void AddCheese(){Debug.Log(Adding the Cheese: Provolone);}protected override void AddVegetables(){Debug.Log(Adding the Vegetables: Tomatoes);}protected override void AddCondiments(){Debug.Log(Adding the Condiments: Vinegar);}}三VeggieHoagie 素菜三明治 public class VeggieHoagie : Hoagie{protected override void AddMeat(){}protected override void AddCheese(){}protected override void AddVegetables(){Debug.Log(Adding the Vegetables: Tomatoes);}protected override void AddCondiments(){Debug.Log(Adding the Condiments: Vinegar);}protected override bool CustomerWantsMeat() { return false; }protected override bool CustomerWantsCheese() { return false; }}四错误的方式 namespace BadExample{// this way you would have to rewrite a lot of code// especially if something changes or another class differs and does e.g. not AddMeat()public class ItalienHoagie{public void MakeSandwich(){CutBun();AddMeat();AddCheese();AddVegtables();AddCondiments();WrapHoagie();}public void CutBun(){Debug.Log(Hoagie is Cut);}public void AddMeat(){Debug.Log(Added Meat);}public void AddCheese(){Debug.Log(Added Cheese);}public void AddVegtables(){Debug.Log(Added Vegies);}public void AddCondiments(){Debug.Log(Added Condiments);}public void WrapHoagie(){Debug.Log(Wrapped Hoagie);}}}五测试 public class TemplateMethodPatternExample1 : MonoBehaviour{void Start(){Hoagie cust12Hoagie new ItalienHoagie();cust12Hoagie.MakeSandwich();Hoagie cust13Hoagie new VeggieHoagie();cust13Hoagie.MakeSandwich();}}
http://www.w-s-a.com/news/969770/

相关文章:

  • 网站建设方维网站标题title为什么不能频繁的改
  • 网站建设如何上传文件wordpress列表自定义数据表
  • 摄影课程自学网站科技项目的类型有
  • 未来最紧缺的十大专业长春seo顾问
  • 为什么点不开网站公关公司是做什么的
  • wordpress主要菜单如何对网站页面进行优化
  • 建设银行深分行圳招聘网站建立互联网公司网站
  • 湖南做旅游网站哪家最好html5手机网站免费模板
  • 云服务器上放多个网站wordpress ping大全
  • 以下属于网站的管理 更新 维护如何才能做好品牌网站建设
  • 国家工业和信息化部网站备案系统网站建设设计费用
  • 网站建设利弊宁波高端网站建设联系方式
  • 网站订票策划方案郑州代做网站
  • 免费的网站加速器注册公司邮箱
  • 千助网站建设网站整站程序
  • 自学建网站做网站优化访问网站出现目录
  • 济南网站建设是什么百度官网登录入口手机版
  • net快速建站西宁手机网站建设
  • 网站浏览器不兼容怎么办软件系统开发大概多少钱
  • 网站建设哪个公司最好shift wordpress
  • 公司网站建设功能介绍室内设计学习
  • 做网站策划容易遇到哪些问题沈阳公司网站制作
  • 做php网站都用框架吗网站备案当面核验拍摄照片
  • 泉州企业自助建站兰州最好的互联网公司
  • 监察部门网站建设方案网站seo技术教程
  • 个人网站制作源代码下载品牌建设部
  • 网站备案需要准备什么文创产品设计思路
  • 网站开发书籍推荐青岛城阳新闻最新消息
  • 秦皇岛网站建设服务聊城做网站的公司资讯
  • 30岁转行做网站设计丰涵网站建设