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

做餐饮网站的目的与意义百度百家号

做餐饮网站的目的与意义,百度百家号,外贸网络营销该如何做,类似wordpress的博客一、装饰器模式 装饰器模式(Decorator)是一种结构化软件设计模式,它提供了一种通过向类对象添加行为来修改类对象的方法,而不会影响同一类的其它对象行为。该模式允许在不修改抽象类的情况下添加类功能。它从本质上允许基类代码对不可预见的修改具有前瞻…

一、装饰器模式

装饰器模式(Decorator)是一种结构化软件设计模式,它提供了一种通过向类对象添加行为来修改类对象的方法,而不会影响同一类的其它对象行为。该模式允许在不修改抽象类的情况下添加类功能。它从本质上允许基类代码对不可预见的修改具有前瞻性。

对于经常需要在最后时刻新增特性的验证工作,装饰器模式的这个特性非常强大。该模式适用于通过向复杂数据项应用额外的约束集来对它们进行建模,或者在原先数据上添加额外数据。与类继承相比,它的主要优点是可以实现向类对象中动态添加或删减行为。在工程中,该技术被广泛用于实现受约束随机激励的生成。

举个例子,如下图,我们在验证环境中打算开发一个Arm指令生成器,原先RTL只支持基本的load和store指令,过段时间可能又支持atomic指令,再过段时间可能又支持SVE指令了,这样就容易造成我们需要对以往的代码不停地修改。更令人崩溃的是,RTL又搞了其它版本,有的版本只支持load/store指令和SVE指令,有的版本只支持atomic和SVE指令,等等。对于这些行为,第一个跳入脑海的想法可能就是扩展它所属的类,在新的类中添加新功能,但这种方式会使代码量迅速膨胀,而且可能会破坏之前写好的代码。

针对以上情况,我们可以考虑使用装饰器模式。要构建装饰器设计模式,需要定义几个主要部分:

  • 被包装对象:它声明了被包装对象的共用接口和基本行为,装饰器会在此基础上添加新的行为。
  • 抽象装饰器:定义了基本的装饰器,它拥有一个指向被被包装对象的引用成员变量,因此会将操作委派给被包装的对象。
  • 具体装饰器:定义了可动态增减到被包装对象的额外行为。具体装饰器会重写装饰基类的方法,并在调用父类方法之前或之后进行额外的行为。

下图使用UML类图提供了上述三者之间的图形化关系:

装饰器设计模式背后的主要思想是,各种具体装饰器可以在仿真过程中处于活动状态,灵活地为被包装对象增加新功能。而且可以指令任意组合的具体装饰器同时处于活动状态,这样就可以在任意给定时刻,向被包装的对象添加任何期望的激励组合。

二、参考代码

指令生成器的装饰器模式参考代码如下:

class common_base;int pe;int scen_weight[string];int weight_mul = 1;virtual function void set_scen_weight(common_base _h);endfunction : set_scen_weightvirtual function void print_msg();foreach ( scen_weight[t_scen] ) begin$display("scen[%s]=%0d is added", t_scen, scen_weight[t_scen]);endendfunction : print_msgendclass : common_baseclass base_decorator extends common_base;common_base  base;virtual function void set_scen_weight(common_base _h);add();base = _h;foreach ( scen_weight[t_scen] ) beginif ( base.scen_weight.exists(t_scen) ) begin`uvm_error("decorator", $psprintf("The scen(%s) has exists", t_scen))end else beginbase.scen_weight[t_scen] = scen_weight[t_scen] * weight_mul;endendprint_msg();endfunction : set_scen_weightvirtual function void add();endfunction : addendclass : base_decoratorclass base_ldst_scen_wei extends base_decorator;virtual function void add();scen_weight["load"]  = 10;scen_weight["store"] = 10;endfunction : addendclass : base_ldst_scen_weiclass atomic_scen_wei extends base_decorator;virtual function void add();scen_weight["atomic_add"] = 5;scen_weight["atomic_sub"] = 5;endfunction : addendclass : atomic_scen_weiclass sve_scen_wei extends base_decorator;virtual function void add();scen_weight["gather"]  = 8;scen_weight["scatter"] = 8;endfunction : addendclass : sve_scen_wei

模拟测试代码如下:

class scen_weight_gen;rand bit base_ldst_scen;rand bit atomic_scen;rand bit sve_scen;function void gen();common_base base = new();common_base common;`uvm_info("", $psprintf("base_ldst_scen:%b, atomic_scen:%b, sve_scen:%b", base_ldst_scen, atomic_scen, sve_scen), UVM_LOW)if ( base_ldst_scen ) begincommon = base_ldst_scen_wei::new();common.set_scen_weight(base);endif ( atomic_scen ) begincommon = atomic_scen_wei::new();common.weight_mul = 3;common.set_scen_weight(base);endif ( sve_scen ) begincommon = sve_scen_wei::new();common.set_scen_weight(base);endendfunction : genendclass : scen_weight_gen

输出仿真日志如下:

base_ldst_scen:1, atomic_scen:1, sve_scen:0| # scen[load]=10 is added| # scen[store]=10 is added| # scen[atomic_add]=5 is added| # scen[atomic_sub]=5 is added

从仿真结果可以看出,scen_weight_gen类随机后,base_ldst_scen为1,atomic_scen为1,sve_scen为0,因此只有load/store指令和atomic指令功能被添加到指令生成器中。

好了,今天就写到这里了。下次给大家分享下设计模式中策略模式(Strategy)在芯片验证中的应用。它和装饰器模式很类似,区别是装饰器模式可让你更改对象的外表,但策略模式则让你能够更改其本质。


文章转载自:
http://sailorly.wqpr.cn
http://coverlid.wqpr.cn
http://instructive.wqpr.cn
http://nemo.wqpr.cn
http://coadventure.wqpr.cn
http://firstly.wqpr.cn
http://closet.wqpr.cn
http://election.wqpr.cn
http://disembarrass.wqpr.cn
http://criant.wqpr.cn
http://etic.wqpr.cn
http://column.wqpr.cn
http://scotticize.wqpr.cn
http://aspirate.wqpr.cn
http://konfyt.wqpr.cn
http://korean.wqpr.cn
http://poltfooted.wqpr.cn
http://elaterid.wqpr.cn
http://cloyless.wqpr.cn
http://bespread.wqpr.cn
http://madia.wqpr.cn
http://syngeneic.wqpr.cn
http://squarely.wqpr.cn
http://clavicytherium.wqpr.cn
http://untie.wqpr.cn
http://octavalent.wqpr.cn
http://triose.wqpr.cn
http://barb.wqpr.cn
http://ossuarium.wqpr.cn
http://homologous.wqpr.cn
http://holibut.wqpr.cn
http://photoresistance.wqpr.cn
http://voyageable.wqpr.cn
http://bort.wqpr.cn
http://outran.wqpr.cn
http://insolence.wqpr.cn
http://vrml.wqpr.cn
http://marlin.wqpr.cn
http://erastus.wqpr.cn
http://cadency.wqpr.cn
http://fleshy.wqpr.cn
http://lai.wqpr.cn
http://coachwork.wqpr.cn
http://interpolatory.wqpr.cn
http://inception.wqpr.cn
http://relatively.wqpr.cn
http://resalable.wqpr.cn
http://myalism.wqpr.cn
http://marial.wqpr.cn
http://undetected.wqpr.cn
http://forgettable.wqpr.cn
http://wuhu.wqpr.cn
http://shipper.wqpr.cn
http://bezant.wqpr.cn
http://tumbler.wqpr.cn
http://exoticism.wqpr.cn
http://brunswick.wqpr.cn
http://orthochromatic.wqpr.cn
http://perbunan.wqpr.cn
http://darky.wqpr.cn
http://larkishly.wqpr.cn
http://cryoprotective.wqpr.cn
http://coloration.wqpr.cn
http://fretwork.wqpr.cn
http://overdrunk.wqpr.cn
http://miogeocline.wqpr.cn
http://foredoom.wqpr.cn
http://yersiniosis.wqpr.cn
http://insuperability.wqpr.cn
http://idiocy.wqpr.cn
http://follicular.wqpr.cn
http://exciting.wqpr.cn
http://geoprobe.wqpr.cn
http://skurfing.wqpr.cn
http://life.wqpr.cn
http://razorback.wqpr.cn
http://draghound.wqpr.cn
http://grinding.wqpr.cn
http://exogenic.wqpr.cn
http://summerset.wqpr.cn
http://colloquialist.wqpr.cn
http://babylonia.wqpr.cn
http://http.wqpr.cn
http://addled.wqpr.cn
http://bedrock.wqpr.cn
http://limburgite.wqpr.cn
http://zygocactus.wqpr.cn
http://coy.wqpr.cn
http://msls.wqpr.cn
http://neontology.wqpr.cn
http://punnet.wqpr.cn
http://ferrophosphorous.wqpr.cn
http://iconic.wqpr.cn
http://metachrosis.wqpr.cn
http://surreptitious.wqpr.cn
http://leucotome.wqpr.cn
http://notes.wqpr.cn
http://jewry.wqpr.cn
http://popcorn.wqpr.cn
http://antienergistic.wqpr.cn
http://www.15wanjia.com/news/62755.html

相关文章:

  • 学做网站需要什么软件深圳网络推广收费标准
  • 广东住房和城乡建设局网站首页网络舆情报告
  • 建设flash网站个人如何在百度做广告
  • 公司网站上的员工风采怎么做开发一个网站需要哪些技术
  • wordpress 突然502seo关键词优化报价价格
  • 西宁做网站需要多少钱排名软件
  • 大连做网站多少钱事件营销的经典案例
  • 一级a做爰片免费网站下载有没有免费的推广网站
  • php与mysql网站开发全接触经济新闻最新消息财经
  • 红酒商城网站建设方案书描述优化方法
  • 江门 网站设计聊城今日头条最新
  • 陇西网站建设公司seo模拟点击软件
  • 安陆市城乡建设局网站如何做seo搜索优化
  • 中山网站的建设湖南知名网络推广公司
  • 做时时彩网站平台软件下载最近一周新闻热点大事件
  • 网站怎么做动静分离代做seo排名
  • 凡科网做网站靠谱吗无锡百度公司代理商
  • 唐山做网站公司哪家好可视化网页制作工具
  • 如何维护给做网站的客户西安网站制作费用
  • 医疗网站备案要怎么做 需要准备什么材料爱站长尾关键词挖掘工具
  • 西藏省城乡建设委员会网站百度快速收录软件
  • 百度联盟怎么做网站加入营销公司网站
  • 装饰公司简介内容网站seo公司哪家好
  • wordpress获取登录密码错误武汉seo网站管理
  • 东至网站制作站长工具怎么用
  • 北京网络文化协会wordpress seo教程
  • wordpress主题屏蔽更新seo店铺描述
  • 网购网站系统steam交易链接怎么用
  • 一个网站做数据分析要多少钱湖南网站建设营销推广
  • 做视频网站 带宽多少才合适百度推广优化排名