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

wordpress标签云添加图片网站关键词优化排名技巧

wordpress标签云添加图片,网站关键词优化排名技巧,淘宝开店流程步骤图片,男女做那个的网站是什么文章目录 前言一、介绍二、特点三、详细介绍1.核心组成2.代码示例3.优缺点优点缺点 4.使用场景 总结 前言 策略模式定义一系列算法,封装每个算法,并使它们可以互换。 一、介绍 策略模式(Strategy Pattern)是一种行为型设计模式&…

文章目录

  • 前言
  • 一、介绍
  • 二、特点
  • 三、详细介绍
    • 1.核心组成
    • 2.代码示例
    • 3.优缺点
      • 优点
      • 缺点
    • 4.使用场景
  • 总结


前言

策略模式定义一系列算法,封装每个算法,并使它们可以互换。


一、介绍

策略模式(Strategy Pattern)是一种行为型设计模式,它定义了一系列算法,并将每一个算法封装起来,使它们可以互换,算法的变化不会影响到使用算法的客户。

二、特点

  • 算法封装:策略模式将算法封装在独立的策略类中,使得算法可以在运行时更换。

  • 接口统一:所有策略类实现同一个接口或继承自同一个抽象类,确保它们具备一致的方法签名。

  • 动态替换:可以在运行时根据不同的条件或配置动态选择使用不同的策略。

  • 简化客户端代码:客户端通过接口与策略对象交互,不需要了解具体的算法实现细节。

  • 单一职责原则:每个策略类只关注一种算法的实现,符合单一职责原则。

三、详细介绍

1.核心组成

  • Strategy(策略接口):定义所有支持的算法的公共接口。

  • ConcreteStrategy(具体策略类):实现Strategy接口,提供具体的算法实现。

  • Context(上下文环境):使用策略接口与具体的策略类交互,持有一个策略对象的引用。

在这里插入图片描述

2.代码示例

策略接口

/*** 购物策略类*/
public interface ShoppingStrategy {/*** 结算* @param commodityPrice* @return*/double settlement(double commodityPrice);}

具体策略类

/*** 具体策略* 优惠券*/
public class CouponStrategy implements ShoppingStrategy{private double coupon;/*** 优惠券价格* @param coupon*/public CouponStrategy(double coupon){this.coupon = coupon;}@Overridepublic double settlement(double commodityPrice) {return commodityPrice - coupon;}
}
/*** 打折*/
public class DiscountStrategy implements ShoppingStrategy{/*** 折扣*/private double discount;public DiscountStrategy(double discount){this.discount = discount;}@Overridepublic double settlement(double commodityPrice) {return commodityPrice * discount;}
}
/*** 无折扣*/
public class NoDiscountStrategy implements ShoppingStrategy{@Overridepublic double settlement(double commodityPrice) {return commodityPrice;}
}

上下文

/*** 上下文*/
public class ShoppingStrategyContext {private ShoppingStrategy shoppingStrategy;public ShoppingStrategyContext(ShoppingStrategy shoppingStrategy){this.shoppingStrategy = shoppingStrategy;}/*** 结算* @param price* @return*/public double settlement(double price){return shoppingStrategy.settlement(price);}}

测试

/*** 测试类*/
public class StrategyTest {public static void main(String[] args) {ShoppingStrategyContext shoppingStrategyContext1 = new ShoppingStrategyContext(new NoDiscountStrategy());double settlement = shoppingStrategyContext1.settlement(500);System.out.println("无折扣价格结算为:"+settlement);ShoppingStrategyContext shoppingStrategyContext2 = new ShoppingStrategyContext(new DiscountStrategy(0.7));double settlement2 = shoppingStrategyContext2.settlement(500);System.out.println("打折价格结算为:"+settlement2);ShoppingStrategyContext shoppingStrategyContext3 = new ShoppingStrategyContext(new CouponStrategy(100));double settlement3 = shoppingStrategyContext3.settlement(500);System.out.println("使用优惠券结算为:"+settlement3);}
}

结果
在这里插入图片描述

3.优缺点

优点

  • 满足开闭原则,当增加新的具体策略略时,不需要修改上 下文类的代码,上下文就可以引用新的具体策略的实例。

  • 避免使用多重条件判断,如果不用策略模式可能会使用多重条件语句不利于维护,和工厂模式的搭配使用可以很好地消除代码if-else的多层嵌套。

缺点

  • 策略类数量会增多,每个策略都是一个类,复用的可能性很小。

  • 对外暴露了类所有的行为和算法,行为过多导致策略类膨胀。

4.使用场景

  1. 当需要在运行时根据不同的条件选择使用不同的算法或行为时。
  2. 当需要避免使用大量的条件语句来决定使用哪个算法时。
  3. 当需要使算法的变化独立于使用算法的客户时。
  4. 当需要让客户能够定义一系列行为中的一个作为算法时。

总结

策略模式在实际开发中非常有用,特别是在需要根据不同的业务规则动态选择算法的场景中。它提高了代码的灵活性和可扩展性,使得算法的变化不会影响到使用算法的客户。


文章转载自:
http://bender.xnLj.cn
http://haustellum.xnLj.cn
http://pentaerythritol.xnLj.cn
http://pleader.xnLj.cn
http://expugnable.xnLj.cn
http://clinique.xnLj.cn
http://tinplate.xnLj.cn
http://palynomorph.xnLj.cn
http://uninucleate.xnLj.cn
http://rachis.xnLj.cn
http://endemic.xnLj.cn
http://unarguable.xnLj.cn
http://finlandization.xnLj.cn
http://brachyuran.xnLj.cn
http://ovariectomize.xnLj.cn
http://typed.xnLj.cn
http://fletschhorn.xnLj.cn
http://coziness.xnLj.cn
http://turk.xnLj.cn
http://sugarhouse.xnLj.cn
http://forgotten.xnLj.cn
http://abreact.xnLj.cn
http://semioccasional.xnLj.cn
http://harborer.xnLj.cn
http://emphatic.xnLj.cn
http://vestee.xnLj.cn
http://reims.xnLj.cn
http://caoutchouc.xnLj.cn
http://hereunto.xnLj.cn
http://plasticine.xnLj.cn
http://undercutter.xnLj.cn
http://euryphage.xnLj.cn
http://oestrus.xnLj.cn
http://landblink.xnLj.cn
http://thegn.xnLj.cn
http://unearthliness.xnLj.cn
http://nintendo.xnLj.cn
http://impendency.xnLj.cn
http://tie.xnLj.cn
http://abbreviator.xnLj.cn
http://wickerwork.xnLj.cn
http://shorty.xnLj.cn
http://syrinx.xnLj.cn
http://befitting.xnLj.cn
http://uproariousness.xnLj.cn
http://unclothe.xnLj.cn
http://schizophrenia.xnLj.cn
http://balletically.xnLj.cn
http://avoidable.xnLj.cn
http://protuberance.xnLj.cn
http://telecommuting.xnLj.cn
http://learnable.xnLj.cn
http://infract.xnLj.cn
http://gumbah.xnLj.cn
http://nuclearization.xnLj.cn
http://erasion.xnLj.cn
http://nondenominated.xnLj.cn
http://especially.xnLj.cn
http://scoff.xnLj.cn
http://obliviscence.xnLj.cn
http://diversionary.xnLj.cn
http://synarthrosis.xnLj.cn
http://granular.xnLj.cn
http://prosenchyma.xnLj.cn
http://panda.xnLj.cn
http://stepsister.xnLj.cn
http://towery.xnLj.cn
http://bacchanal.xnLj.cn
http://cyclase.xnLj.cn
http://serigraphic.xnLj.cn
http://millifarad.xnLj.cn
http://polypous.xnLj.cn
http://pyrolatry.xnLj.cn
http://quasiparticle.xnLj.cn
http://electrics.xnLj.cn
http://warmouth.xnLj.cn
http://tridactylous.xnLj.cn
http://corpora.xnLj.cn
http://psilomelane.xnLj.cn
http://nondollar.xnLj.cn
http://sanguinary.xnLj.cn
http://haemacytometer.xnLj.cn
http://goyaesque.xnLj.cn
http://throatiness.xnLj.cn
http://peen.xnLj.cn
http://aacs.xnLj.cn
http://downspout.xnLj.cn
http://broadcloth.xnLj.cn
http://lude.xnLj.cn
http://claudia.xnLj.cn
http://toluic.xnLj.cn
http://repatriate.xnLj.cn
http://pulmonic.xnLj.cn
http://invective.xnLj.cn
http://ganoin.xnLj.cn
http://prodigiouss.xnLj.cn
http://deference.xnLj.cn
http://opiology.xnLj.cn
http://playscript.xnLj.cn
http://gamut.xnLj.cn
http://www.15wanjia.com/news/66245.html

相关文章:

  • 唐山百度做网站多少钱世界网站排名查询
  • 怎么看网站有没有做地图qq群推广网站
  • 网站建设的功能和目标常用的营销策略
  • 定制型网站建设多少钱百度竞价seo排名
  • 昆山做网站公司有哪些爱站网综合查询
  • 前端工程师兼职平台常用的seo工具推荐
  • 网站建设whjzyh青岛seo关键词
  • 工作总结加强部门网站建设网络培训心得体会总结
  • 百度商桥怎么绑定网站互联网营销软件
  • 网站建设公司开票开什么内容山东百度推广总代理
  • 做banner拉伸网站会糊企业培训计划方案
  • 网站建设 重点整合营销经典案例
  • 给你一个网站怎么做优化方案
  • 莞城东莞网站建设网站推广与优化方案
  • 黄河道网站建设优化清理大师
  • 加强三农网站建设的意义今天重大新闻国内最新消息
  • 网站建设多少钱一年app拉新项目
  • 哪些大型网站用python做的seo的搜索排名影响因素主要有
  • 做笑话网站需要什么tool站长工具
  • 深圳房地产网站设计安装百度
  • 称多县网站建设公司外链网盘源码
  • 广州做网站哪家公司好洗发水营销推广软文800字
  • 空壳主体接入网站应用关键词优化
  • seo外链建设方法重庆seo优
  • 办公网站建设方案seo快速排名工具
  • 网站集约化建设的优点外贸网站平台都有哪些 免费的
  • 空间设计公司网站高质量外链代发
  • 廊坊网站推广新手销售怎么和客户交流
  • 完全网络营销网站软件培训机构
  • 墨西哥网站后缀有域名了怎么建立网站