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

大兴网站建设价格个人简介代码网页制作模板

大兴网站建设价格,个人简介代码网页制作模板,曹县网站建设公司,阳江企业网站排名优化新旧代码对比 策略模式 基本概念 策略模式是一种行为设计模式#xff0c;它定义了一系列算法#xff0c;将每个算法封装起来#xff0c;并且使它们可以互相替换。策略模式允许客户端选择算法的具体实现#xff0c;而不必改变客户端的代码。这样#xff0c;客户端代码就…新旧代码对比 策略模式 基本概念 策略模式是一种行为设计模式它定义了一系列算法将每个算法封装起来并且使它们可以互相替换。策略模式允许客户端选择算法的具体实现而不必改变客户端的代码。这样客户端代码就可以根据需要在不同的算法之间切换。 在你提供的代码中AnalysisPortCodeStrategy 接口就是一个策略接口而实现该接口的具体类可能有多个就是策略类。每个具体的实现类都代表了一种不同的算法或策略用于处理特定的业务逻辑。 在策略模式中通常有三个角色 策略接口Strategy Interface 定义一个策略的接口或抽象类声明了具体策略类需要实现的方法。 public interface AnalysisPortCodeStrategy {ListAnalysisPortCodeInfoBO getAnalysisPortCodeInfo(GeneralAnalysisQueryParamVO queryParamVO);// 其他方法... }具体策略类Concrete Strategies 实现了策略接口具体定义了算法的实现。 public class StrategyA implements AnalysisPortCodeStrategy {Overridepublic ListAnalysisPortCodeInfoBO getAnalysisPortCodeInfo(GeneralAnalysisQueryParamVO queryParamVO) {// 具体算法A的实现// ...} }public class StrategyB implements AnalysisPortCodeStrategy {Overridepublic ListAnalysisPortCodeInfoBO getAnalysisPortCodeInfo(GeneralAnalysisQueryParamVO queryParamVO) {// 具体算法B的实现// ...} }上下文类Context 包含一个策略接口的引用可以在运行时切换不同的具体策略。 public class AnalysisContext {private AnalysisPortCodeStrategy strategy;public AnalysisContext(AnalysisPortCodeStrategy strategy) {this.strategy strategy;}public void setStrategy(AnalysisPortCodeStrategy strategy) {this.strategy strategy;}public ListAnalysisPortCodeInfoBO executeStrategy(GeneralAnalysisQueryParamVO queryParamVO) {return strategy.getAnalysisPortCodeInfo(queryParamVO);} }学习文章https://zhuanlan.zhihu.com/p/168682592 优点 使用策略模式的好处主要在于灵活性和可维护性。下面是一些使用策略模式的优势 可扩展性 策略模式使得你能够轻松地添加新的播放模式而不必修改主类的代码。如果你要添加新的播放模式只需创建新的策略类而不会影响到其他部分的代码。 可维护性 每个播放模式都被封装在独立的策略类中这使得每个策略的逻辑都相对较小易于理解和维护。这种分离使得修改或调整一个播放模式的行为变得更容易而不必涉及主类的复杂逻辑。 解耦合 主类与具体的播放策略相互解耦合这意味着它们彼此不直接依赖。这种解耦合有助于保持代码的清晰度减少代码的复杂性并使得单独测试每个播放策略变得更容易。 动态切换 由于策略是在运行时设置的你可以动态地切换播放策略而不需要停止整个应用程序。这对于需要根据不同条件或用户输入改变行为的情况很有用。 实战改代码 //如果是2.play 初始化播放初始化播放模式设置option参数//同时修正播放视频名称将3D模式的上下左右交错全部取左右作为视频源if (fileBasicReq.getVideoName().contains(_3DM_TD.mp4)) {//上下模式if (fileBasicReq.getAction().equals(play)) {fileCplusplusReq.setOption(topDown);}//实际video都是原视频_3DM_LR.mp4即07-05-58_3DM_LR.mp4原视频为左右模式realVideoName fileBasicReq.getVideoName().substring(0, 8) _3DM_LR.mp4;} else if (fileBasicReq.getVideoName().contains(_3DM_CL.mp4)) {//交错模式if (fileBasicReq.getAction().equals(play)) {fileCplusplusReq.setOption(cross);}//实际video都是原视频_3DM_LR.mp4即07-05-58_3DM_LR.mp4原视频为左右模式realVideoName fileBasicReq.getVideoName().substring(0, 8) _3DM_LR.mp4;} else if (fileBasicReq.getVideoName().contains(_3DM_LR.mp4)) {//左右模式if (fileBasicReq.getAction().equals(play)) {fileCplusplusReq.setOption(leftRight);}} else if (fileBasicReq.getVideoName().contains(_2DM_LE.mp4) || fileBasicReq.getVideoName().contains(_2DM_RE.mp4)) {//2D模式if (fileBasicReq.getAction().equals(play)) {fileCplusplusReq.setOption(2d);}} else {log.error(非预期效果);throw new BusinessException(找不到对应的播放模式);}fileCplusplusReq.setVideoPath(fileBasicReq.getVideoRootPath().substring(1) / realVideoName);}新代码 //如果是2.play 初始化播放初始化播放模式设置option参数//同时修正播放视频名称将3D模式的上下左右交错全部取左右作为视频源// 使用策略VideoPlayer videoPlayer new VideoPlayer();if (fileBasicReq.getVideoName().contains(_3DM_TD.mp4)) {videoPlayer.setPlayStrategy(new TopDownStrategy());} else if (fileBasicReq.getVideoName().contains(_3DM_CL.mp4)) {videoPlayer.setPlayStrategy(new CrossStrategy());} else if (fileBasicReq.getVideoName().contains(_3DM_LR.mp4)) {videoPlayer.setPlayStrategy(new LeftRightStrategy());} else if (fileBasicReq.getVideoName().contains(_2DM_LE.mp4) || fileBasicReq.getVideoName().contains(_2DM_RE.mp4)) {videoPlayer.setPlayStrategy(new TwoDStrategy());} else {throw new BusinessException(找不到对应的播放模式);}if (fileBasicReq.getAction().equals(play)) {videoPlayer.playStrategy.apply(fileCplusplusReq, fileBasicReq);}}package com.wg.strategy;import com.wg.model.FileBasicReq; import com.wg.model.FileCplusplusReq;public interface VideoPlayStrategy {void apply(FileCplusplusReq fileCplusplusReq, FileBasicReq fileBasicReq); }package com.wg.strategy;public class VideoPlayer {public VideoPlayStrategy playStrategy;public void setPlayStrategy(VideoPlayStrategy playStrategy) {this.playStrategy playStrategy;} } 这里只写了其中一种策略 package com.wg.strategy;import com.wg.model.FileBasicReq; import com.wg.model.FileCplusplusReq;// 上下模式策略 public class TopDownStrategy implements VideoPlayStrategy {Overridepublic void apply(FileCplusplusReq fileCplusplusReq, FileBasicReq fileBasicReq) {fileCplusplusReq.setOption(topDown);modifyVideoNameFor3D(fileCplusplusReq, fileBasicReq);}private void modifyVideoNameFor3D(FileCplusplusReq fileCplusplusReq, FileBasicReq fileBasicReq) {// 修改视频名称逻辑例如将_3DM_TD.mp4修改为对应的左右模式名称fileCplusplusReq.setVideoPath(fileBasicReq.getVideoRootPath().substring(1) / fileBasicReq.getVideoName().substring(0, 8) _3DM_LR.mp4);} }
http://www.dnsts.com.cn/news/251883.html

相关文章:

  • 国际网站排名查询重庆推广渠道
  • 公司的网站 优帮云第三次网站建设的通报
  • 北京做网站公司推荐1做网站的公司
  • 利用网盘做视频网站wordpress 整站模板
  • 网页与网站设计 什么是属性企信网查询官网
  • 湛江做网站的公司产品免费推广网站有哪些
  • 网站运营内容建设方案全网市场营销服务(上海)有限公司
  • 网站开发制作平台高端定制网站
  • 西双版纳网站建设开发公司科技企业网站建设
  • App网站建设 高品质网站建设图片展示网站php源码
  • 七牛上传wordpressseo优化设计
  • 邢台网站建设哪儿好网络推广龙岗比较好的
  • 网站后缀gov手机wap端
  • phpcmsv9手机网站开发怎样做才能提升自己的网站
  • 网站开发建站微信公众号小程序跨境电商网站系统开发
  • 广州做网站信科分公司卖网格布怎样做网站
  • 易营宝mip网站建设网站城市切换如何做
  • 网站主题和风格wordpress图片合成
  • 无锡知名网站国内经典网站
  • 网站怎么申请官网个人简历在线编辑文档
  • 海南海口网站开发公司阜阳交通建设工程质监局网站
  • 科技网站配色方案企业营销型网站系统
  • 店铺外卖网站怎么做网站建设客户需求表
  • 微信微网站模板下载网站公司备案通知
  • 网站色调选择广州网站建设论坛
  • 网站建设费用做无形资产凯里网站设计
  • 宁波网站建设建站厂家赞片cms
  • 公司网站制作公司排名黄页网站推广app
  • 用word做网站功能结构图wordpress找回管理员密码
  • 炫酷网站建设广州市天河区工程建设监督网站