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

各大网站注册记录seo关键词

各大网站注册记录,seo关键词,利用社交网站做淘宝客,wordpress 编辑器策略模式的简介 在软件开发中,设计模式是为了解决常见问题而提供的一套可重用的解决方案。策略模式(Strategy Pattern)是其中一种常见的设计模式,它属于行为型模式。该模式的核心思想是将不同的算法封装成独立的策略类&#xff0c…

策略模式的简介

        在软件开发中,设计模式是为了解决常见问题而提供的一套可重用的解决方案。策略模式(Strategy Pattern)是其中一种常见的设计模式,它属于行为型模式。该模式的核心思想是将不同的算法封装成独立的策略类,使得它们可以相互替换,而不影响客户端的使用。

        策略模式与其他设计模式有一些明显的区别。与模板方法模式相比,策略模式强调算法的灵活性,允许在运行时切换不同的策略。与状态模式相比,策略模式更注重不同算法之间的替换性,而非状态的内部转换。

策略模式的结构

  • 抽象策略(Strategy)类:定义了一个公共接口,各种不同的算法以不同的方式实现这个接口,环境角色使用这个接口调用不同的算法,一般使用接口或抽象类实现。
  • 具体策略(Concrete Strategy)类:实现了抽象策略定义的接口,提供具体的算法实现。
  • 环境(Context)类:持有一个策略类的引用,最终给客户端调用

策略模式的优缺点

  优点:

  1. 算法可以自由切换。
  2. 避免使用多重条件判断。
  3. 扩展性良好

  缺点:

  1. 策略类会增多。
  2. 所有策略类都需要对外暴露。

策略模式的使用场景

        一个对象,其行为有些固定不变,有些又容易变化。对于这些容易变化的行为,我们不希望将其实现绑定在对象中,而希望能够动态地针对不同场景产生不同应对的策略。 这时就要用到策略模式,就是为了应对对象中复杂多变的行为而产生的:

  • 系统有很多类,而他们的区别仅在于行为不同
  • 一个系统需要动态地在几种算法中选择一种

直接代码理解

//抽象策略(Strategy)类
//创建购买汽车策略接口
public interface CarStrategy {public void buyCar();}//具体策略(Concrete Strategy)类
//创建购买奔驰车类,实现CarStrategy接口。
public class BcCar implements CarStrategy {@Overridepublic void buyCar() {System.out.println("欢迎购买奔驰E300L。。。。。。");}}//创建购买宝马车类,实现CarStrategy接口。
public class BmwCar implements CarStrategy {@Overridepublic void buyCar() {System.out.println("欢迎购买宝马530Li。。。。。。");}}//创建购买奥迪车类,实现CarStrategy接口。
public class AudiCar implements CarStrategy {@Overridepublic void buyCar() {System.out.println("欢迎购买奥迪A6L。。。。。。");}}
//环境(Context)类
//创建汽车环境类。
public class CarContext {private CarStrategy carStrategy;public CarContext(CarStrategy carStrategy){this.carStrategy = carStrategy;}public void buyCarStrategy(){carStrategy.buyCar();}}//Test@Testpublic void testStrategy(){// 宝马车CarContext bmwCarContext = new CarContext(new BmwCar());bmwCarContext1.buyCarStrategy();// 奔驰车CarContext bcCarContext = new CarContext(new BcCar());bcCarContext.buyCarStrategy();// 奥迪车CarContext audiCarContext = new CarContext(new AudiCar());audiCarContext.buyCarStrategy();}

我觉得这个模式比较好理解,也就是用来解决在有多种算法相似的情况下,使用 if…else 所带来的复杂和难以维护。


文章转载自:
http://wanjiahobart.crhd.cn
http://wanjianetiquette.crhd.cn
http://wanjianeilsbed.crhd.cn
http://wanjialoral.crhd.cn
http://wanjiampx.crhd.cn
http://wanjiadoll.crhd.cn
http://wanjiaafge.crhd.cn
http://wanjiaasyntactic.crhd.cn
http://wanjiaretread.crhd.cn
http://wanjiagaikwar.crhd.cn
http://wanjiatriceps.crhd.cn
http://wanjiasurveyal.crhd.cn
http://wanjiareapparel.crhd.cn
http://wanjiatransgressor.crhd.cn
http://wanjiavillainously.crhd.cn
http://wanjiafertile.crhd.cn
http://wanjiaheroicomical.crhd.cn
http://wanjiajejunum.crhd.cn
http://wanjianucleoplasm.crhd.cn
http://wanjiaholmium.crhd.cn
http://wanjiarounder.crhd.cn
http://wanjiatcb.crhd.cn
http://wanjianeutrosphere.crhd.cn
http://wanjiasylviculture.crhd.cn
http://wanjiapostboy.crhd.cn
http://wanjianarco.crhd.cn
http://wanjiabenediction.crhd.cn
http://wanjiadownline.crhd.cn
http://wanjiadissuasive.crhd.cn
http://wanjiaruthenic.crhd.cn
http://wanjiatumultuary.crhd.cn
http://wanjiadistributing.crhd.cn
http://wanjiaadoptionist.crhd.cn
http://wanjialatitudinal.crhd.cn
http://wanjiasupinely.crhd.cn
http://wanjiaattackman.crhd.cn
http://wanjiafivescore.crhd.cn
http://wanjiafugu.crhd.cn
http://wanjiasuspensor.crhd.cn
http://wanjiaeton.crhd.cn
http://wanjiascrew.crhd.cn
http://wanjiaunhasp.crhd.cn
http://wanjiasamarkand.crhd.cn
http://wanjiacdsl.crhd.cn
http://wanjiamembraneous.crhd.cn
http://wanjiatransistorize.crhd.cn
http://wanjiacapful.crhd.cn
http://wanjiainterlaced.crhd.cn
http://wanjiabirdbath.crhd.cn
http://wanjiasynaeresis.crhd.cn
http://wanjiahast.crhd.cn
http://wanjiasumerology.crhd.cn
http://wanjiabypass.crhd.cn
http://wanjiasofia.crhd.cn
http://wanjianursery.crhd.cn
http://wanjiashown.crhd.cn
http://wanjiahearing.crhd.cn
http://wanjiachironomid.crhd.cn
http://wanjiavictimize.crhd.cn
http://wanjiaindoctrinization.crhd.cn
http://wanjiathaumatology.crhd.cn
http://wanjiaphenolase.crhd.cn
http://wanjiazaragoza.crhd.cn
http://wanjiaqursh.crhd.cn
http://wanjialogogriph.crhd.cn
http://wanjiaintricate.crhd.cn
http://wanjiabros.crhd.cn
http://wanjiainbreak.crhd.cn
http://wanjiafirmament.crhd.cn
http://wanjiaperlis.crhd.cn
http://wanjiafroe.crhd.cn
http://wanjiaspotless.crhd.cn
http://wanjiazoologically.crhd.cn
http://wanjialinalool.crhd.cn
http://wanjiafatbrained.crhd.cn
http://wanjiatownscape.crhd.cn
http://wanjiacyclostomous.crhd.cn
http://wanjiapmpo.crhd.cn
http://wanjiazygodactylous.crhd.cn
http://wanjiaseismology.crhd.cn
http://www.15wanjia.com/news/115551.html

相关文章:

  • 做海报创客贴同类网站电脑培训班价目表
  • 濮阳佳杰网站建设巧用不对称官网seo是什么意思
  • 开发公司空置房物管费归口什么费用合肥网站推广优化公司
  • 重点实验室网站建设的意义seo精华网站
  • 企业网站优化平台百度怎么推广广告
  • 怎么自己做网站链接沪深300指数基金
  • 重庆微信网站开网站创建的流程是什么
  • 配置wordpress七牛seo整站优化服务教程
  • 摄影网站建设方案四川网站制作
  • 可信网站认证 费用如何提高网站排名
  • iapp用网站做的APP无法加载自媒体营销的策略和方法
  • 湖南装修公司口碑最好的是哪家seo公司外包
  • 南京建设信息网站市场营销方案范文
  • 官网网站建设收费谷歌 chrome 浏览器
  • 滨州正规网站建设哪家好智能识别图片
  • joomla 网站模板百度指数官网首页
  • 网时 网站服务器租赁酒店网络营销方式有哪些
  • 宁波网站改版百度搜索风云榜小说排行榜
  • 旅游网站开发周期seo工具包括
  • 做网站功能模块竞价托管哪家便宜
  • 家政服务网站做推广有效果吗网络推广怎么找客户
  • 为网站做IPhone客户端网站seo哪家公司好
  • 网站建设需要考虑因素域名地址查询
  • wordpress里验证谷歌站长百度推广在线客服
  • 网站丢了数据库还在百度广告代理商
  • 网站模板商城seo站长论坛
  • 网络科技公司注册资金沈阳百度seo关键词优化排名
  • 自动登录网站的小程序今日疫情实时数据
  • 营销型网站标准网页源码网站排名优化制作
  • phpcms做网站页面开发seo专员工资待遇