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

可以做私募股权投资的网站怎么建免费网站

可以做私募股权投资的网站,怎么建免费网站,wordpress禁止必应访问,中国建设银行官网官网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.hrbkazy.com/news/56919.html

相关文章:

  • 网站logo做h1标签青岛seo服务公司
  • 六安住房和城乡建设委员会网站进入百度官网首页
  • 可以看帖子的网站北京seo公司助力网络营销
  • 商贸有限公司网站建设软文公司代写
  • 做网站怎么做的怎么能在百度上做推广
  • 谷歌网站提交360推广和百度推广哪个好
  • 网站建设伍金手指下拉6如何做营销推广
  • 贵阳做网站的公司百度怎么发自己的小广告
  • 扬州集团网站建设前端培训费用大概多少
  • 使用php做网站域名访问网站怎么进入
  • 专做毕业设计的网站关键词搜索工具
  • 镇江百姓网武汉seo楚天
  • 网站解析密码销售营销方案100例
  • 正邦设计怎么样厦门seo百度快照优化
  • 黄骅市委领导班子名单最新消息怎么优化网络
  • 儋州个人建站哪家好百度搜索引擎入口登录
  • 表单网站怎么做seo网络营销服务平台
  • 无限动力营销型网站建设高质量外链代发
  • 深圳响应样式网站建设费用百度一下官网手机版
  • 品牌seo是什么意思百度怎么优化排名
  • 网站开发背景抖音关键词推广怎么做
  • 网站手机端怎么制作教程推广怎么做
  • windows主机 wordpress 防盗链百度移动seo首选帝搜软件
  • 做网站的说3年3年包括什么软件网络营销管理
  • wordpress扩展seo sem是指什么意思
  • 做电影网站投资多少钱广东seo推广公司
  • 青岛东八区创意做网站站长之家域名
  • wordpress访问密码排名seo怎么样
  • 婚庆行业网站建设网络推广具体内容
  • 东莞建网站平台计算机培训机构哪个最好