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

花生壳申请了域名 怎么做网站外链发布

花生壳申请了域名 怎么做网站,外链发布,杭州企业网站建设公司,企业所得税优惠政策最新2023计算新旧代码对比 策略模式 基本概念 策略模式是一种行为设计模式,它定义了一系列算法,将每个算法封装起来,并且使它们可以互相替换。策略模式允许客户端选择算法的具体实现,而不必改变客户端的代码。这样,客户端代码就…

新旧代码对比

策略模式

基本概念

策略模式是一种行为设计模式,它定义了一系列算法,将每个算法封装起来,并且使它们可以互相替换。策略模式允许客户端选择算法的具体实现,而不必改变客户端的代码。这样,客户端代码就可以根据需要在不同的算法之间切换。

在你提供的代码中,AnalysisPortCodeStrategy 接口就是一个策略接口,而实现该接口的具体类(可能有多个)就是策略类。每个具体的实现类都代表了一种不同的算法或策略,用于处理特定的业务逻辑。

在策略模式中,通常有三个角色:

策略接口(Strategy Interface): 定义一个策略的接口或抽象类,声明了具体策略类需要实现的方法。

public interface AnalysisPortCodeStrategy {List<AnalysisPortCodeInfoBO> getAnalysisPortCodeInfo(GeneralAnalysisQueryParamVO queryParamVO);// 其他方法...
}

具体策略类(Concrete Strategies): 实现了策略接口,具体定义了算法的实现。

public class StrategyA implements AnalysisPortCodeStrategy {@Overridepublic List<AnalysisPortCodeInfoBO> getAnalysisPortCodeInfo(GeneralAnalysisQueryParamVO queryParamVO) {// 具体算法A的实现// ...}
}public class StrategyB implements AnalysisPortCodeStrategy {@Overridepublic List<AnalysisPortCodeInfoBO> 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 List<AnalysisPortCodeInfoBO> 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.yayakq.cn/news/971579/

相关文章:

  • 哪个网站有介绍拿到家做的手工活为什么网站开发成本高
  • 网站的技术建设建网页和建网站
  • 太原新建火车站嵌入式软件能干一辈子
  • 建筑参考网站wordpress修改首页模板文件
  • 桂林做网站公司有哪些天津广告设计公司
  • 专门做淘宝代运营的网站添加了字体为什么wordpress
  • 大型网站建设定制开发企业网站功能描述
  • 教学网站前台模板制作wordpress页面模板下载
  • 上海网站设计专注乐云seo王烨桦
  • 房产网站做那个比较好百度网站的优点
  • 临沂网站案例网站上线后做什么
  • 网站建设用什么服务器正规男科医院收费标准
  • 做网络写手最好进那个网站大型seo公司
  • 怎么做企业网站优化爱站网官网关键词查询
  • 怎么知道一个网站是哪家公司做的建设网站公司谁家好
  • 兰州做网站咨询兰州做网站公司网站数据查询
  • 企业建立网站scratch编程
  • 范县网站建设费用如何通过建设网站赚钱
  • 宁国做网站的公司dart 网站开发
  • 基础建设的网站有哪些内容沈阳大熊网站建设制作
  • 如何做彩票网站的源码鸿星尔克网络营销
  • 佛山优化网站安装wordpress 500错误
  • 网站设计好以后怎么上线基于html5的wordpress
  • 网站建设这门课好学吗淘宝网页设计多少钱
  • 金融类的网站怎么做wordpress query_posts参数
  • 网站上可以做文字链接么网站建设规划书费用预算
  • 四川建设集团有限公司网站ASP.NET与网站开发实践教程
  • 广州网站建设报价单北极星招聘网
  • 网站各个功能模块网站开发所需技术
  • 岳阳网站建设与设计WordPress大前端设置背景