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

网站开发的目的和意义线上推广员是做什么的

网站开发的目的和意义,线上推广员是做什么的,北京装修公司报价,wordpress企业网站cms策略模式 1.策略接口 定义一组算法或操作的通用接口,通常是一个抽象类或接口。该接口声明了策略类所必须实现的方法。 示例: class Strategy {doOperation() {} }2.具体策略 实现策略接口,提供具体的算法实现。每个具体策略类负责处理一…

策略模式

1.策略接口

定义一组算法或操作的通用接口,通常是一个抽象类或接口。该接口声明了策略类所必须实现的方法。

示例:

class Strategy {doOperation() {}
}
2.具体策略

实现策略接口,提供具体的算法实现。每个具体策略类负责处理一种特定的情况或算法。它包含了实际的业务逻辑。

示例:

class ConcreteStrategyA extends Strategy {doOperation() {// 具体的算法实现}
}class ConcreteStrategyB extends Strategy {doOperation() {// 具体的算法实现}
}
3.上下文

维持一个对策略对象的引用,负责将客户端的请求委派给具体的策略。上下文通常会包含一个接口,使得客户端可以动态地切换策略。

示例:

class Context {constructor(strategy) {this.strategy = strategy;}setStrategy(strategy) {this.strategy = strategy;}executeStrategy() {this.strategy.doOperation();}
}
分数等级的案例:

假设我们有一个评分系统,根据用户的得分将其分为不同的等级。我们可以使用策略模式来实现这个例子,根据用户得分的不同区间采用不同的评级策略。以下是一个简单的JavaScript实现:

// 策略接口
class GradeStrategy {getGrade(score) {}
}// 具体策略 - 优秀
class ExcellentGradeStrategy extends GradeStrategy {getGrade(score) {if (score >= 90 && score <= 100) {return '优秀';}return null; // 不在该策略范围内返回null}
}// 具体策略 - 良好
class GoodGradeStrategy extends GradeStrategy {getGrade(score) {if (score >= 80 && score < 90) {return '良好';}return null;}
}// 具体策略 - 及格
class PassGradeStrategy extends GradeStrategy {getGrade(score) {if (score >= 60 && score < 80) {return '及格';}return null;}
}// 上下文
class ScoreContext {constructor() {this.strategies = [];}addStrategy(strategy) {this.strategies.push(strategy);}getGrade(score) {for (const strategy of this.strategies) {const grade = strategy.getGrade(score);if (grade) {return grade;}}return '不及格'; // 默认策略}
}// 使用策略模式
const context = new ScoreContext();const excellentStrategy = new ExcellentGradeStrategy();
const goodStrategy = new GoodGradeStrategy();
const passStrategy = new PassGradeStrategy();context.addStrategy(excellentStrategy);
context.addStrategy(goodStrategy);
context.addStrategy(passStrategy);console.log(context.getGrade(95)); // 输出: 优秀
console.log(context.getGrade(85)); // 输出: 良好
console.log(context.getGrade(70)); // 输出: 及格
console.log(context.getGrade(55)); // 输出: 不及格
http://www.hrbkazy.com/news/30284.html

相关文章:

  • 做同城网站还有机会吗个人怎么做网站
  • 临淄网站推广b2b自动发布信息软件
  • 做问卷比较好的网站临沂seo整站优化厂家
  • 海口专业的网站开发搜索引擎入口大全
  • 怎么做万网网站吗网络营销步骤
  • 新网站建设流程重庆百度seo整站优化
  • 网站ui设计标准爱战网关键词挖掘
  • 青海做网站哪家好济南网站推广优化
  • 用wordpress建网站如何用网站模板建站
  • 网站大全官网公关公司排名
  • 蛋糕网站建设方案百度搜索资源平台token
  • 如何做网站打广告河南平价的seo整站优化定制
  • 关于网站建设申请百度如何添加店铺位置信息
  • 北京政府网官网宁波seo快速优化平台
  • 网站开发与设计毕业论文今天重大新闻
  • 门户网站建设管理工作搜索引擎营销是什么意思
  • 广州企业网站建设推荐网站免费软件
  • 正规的合肥网站建设价格潍坊做网站公司
  • 优化大师网站如何打百度人工电话
  • 陕煤建设集团铜川分公司网站百度排名查询
  • 邵阳做网站哪家好北京seo推广
  • 做网站配置搜索引擎优化的主要策略
  • 建一个信息网站多少钱房地产新闻最新消息
  • 网站建设托管公司交换友情链接的目的
  • 达州达县网站建设头条发布视频成功显示404
  • 微信平台服务电话惠州百度seo在哪
  • 网页设计师培训学费大连seo顾问
  • 网站建设技术进行开发广州的百度推广公司
  • 商城网站源码下载网店推广有哪些方法
  • 个人网站怎么做银行卡支付如何宣传推广产品