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

网站打开空白页面挂机宝做网站可以吗

网站打开空白页面,挂机宝做网站可以吗,国内精美网站欣赏,重庆镇海seo整站优化价格Unity实现设计模式——模板方法模式 模板模式(Template Pattern), 指在一个抽象类公开定义了执行它的方法的模板。它的子类可以按需要重写方法实现,但调用将以抽象类中定义的方式进行。 简单说, 模板方法模式定义一个操作中的算法的骨架&…

Unity实现设计模式——模板方法模式

模板模式(Template Pattern), 指在一个抽象类公开定义了执行它的方法的模板。它的子类可以按需要重写方法实现,但调用将以抽象类中定义的方式进行。
简单说, 模板方法模式定义一个操作中的算法的骨架,而将这些步骤延迟到子类中,使得子类可以不改变一个算法的结构,就可以重定义该算法的某些特定步骤。

在这里插入图片描述
注意模板方法模式和策略模式的区别
模板模式注意强调了抽象类公开定义了一个执行的模板方法,而策略模式是对单个算法的封装更具有独立性

下面使用两个例子去介绍模板方法模式:

1.第一个例子(使用比较抽象的例子)

(一)AbstractClass

abstract class AbstractClass
{public abstract void PrimitiveOperation1();public abstract void PrimitiveOperation2();// The "Template method"public 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.yayakq.cn/news/470965/

相关文章:

  • APP开发网站建设哪家好python做网页
  • 数据库网站开发外文翻译保定网站建设设计
  • 重庆网站备案注销杭州做官网的有哪些公司
  • 网站开发的几个主要阶段家在深圳光明业主论坛
  • 遵义做百度网站一年多少钱温州市微网站制作电话
  • 购物网站 开发网站设计公司深圳
  • 合肥网站建设推广服务佛山用户网站建设
  • 默认网站预览能能显示建设中外贸公司销售渠道
  • 网站开发典型360度实景地图下载
  • 网站后台字体安装广安公司网站建设
  • 怎么把自己的网站做自适应网站江苏城乡建设
  • 自己怎么个人网站公司注册地址要求
  • 辉玲建设集团有限公司网站wordpress 打赏
  • 个人php网站济南建设设备安装有限责任公司
  • 北京网站建设设计公司深圳营销型网站建设哪家好
  • 导航网站怎么做seo大型门户网站建设效果好吗
  • 湖北网站建设哪家专业自己的电脑做网站云存储
  • 电商网站需求分析什么值得买 网站开发
  • 平远县建设工程交易中心网站数字化营销系统
  • 网站建设需要些什么东西西安城乡住房建设厅网站首页
  • 商洛网站开发智慧团建密码一般是什么
  • 芜湖网站建设价格值得浏览的国外网站
  • 桂林做网站的公司哪家最好燃灯seo
  • 自己可以做微网站吗网页界面设计是什么
  • 做网站用jsp还是html网站强制qq弹窗代码
  • 湖南营销网站建设设计ps为什么做不了视频网站
  • 北京网站建设最便宜的公司哪家好国内重大新闻
  • 大连网站建设详细流程品牌vi设计升级
  • 襄阳哪里做网站北京信息
  • 专业做国际网站自适应网站开发教程