当前位置: 首页 > news >正文 vs做网站建设商务网站ppt news 2025/10/24 22:43:24 vs做网站,建设商务网站ppt,如何做强一个网站的品牌,公司取名网免费版策略模式是一种行为设计模式#xff0c;它定义了一系列算法#xff0c;将每个算法封装成一个对象#xff0c;并使它们可以互换。策略模式使得算法的变化可以独立于使用算法的客户端。在策略模式中#xff0c;有三个核心角色#xff1a;策略接口#xff08;Strategy#… 策略模式是一种行为设计模式它定义了一系列算法将每个算法封装成一个对象并使它们可以互换。策略模式使得算法的变化可以独立于使用算法的客户端。在策略模式中有三个核心角色策略接口Strategy、具体策略ConcreteStrategy、以及上下文Context。① 策略接口Strategy定义了一个算法族的接口。② 具体策略ConcreteStrategy实现了策略接口封装了具体的算法实现。③ 上下文Context维护一个对策略对象的引用负责将客户端请求委托给具体的策略对象。策略模式的核心思想是将算法的定义与使用分离使得算法可以独立于客户端进行变化、扩展和替换。 1、场景设计 实现场景设计A、B两种策略同一个客户端可以根据需要从两种策略中选择使用。 2、C实现 Strategy 是策略接口定义了一个纯虚的 execute() 方法。ConcreteStrategyA 和 ConcreteStrategyB 是具体策略分别实现了 execute() 方法来执行具体的算法。Context 是上下文持有一个策略对象的指针并且负责将客户端的请求委托给具体的策略对象。在 main() 函数中我们创建了两个具体策略对象然后通过 Context 对象执行了这些策略。 #include iostream// 策略接口 class Strategy {public:virtual void execute() 0; };// 具体策略A class ConcreteStrategyA : public Strategy {public:void execute() override {std::cout Executing strategy A std::endl;} };// 具体策略B class ConcreteStrategyB : public Strategy {public:void execute() override {std::cout Executing strategy B std::endl;} };// 上下文 class Context {private:Strategy *strategy;public:Context(Strategy *strat) : strategy(strat) {}void setStrategy(Strategy *strat) {strategy strat;}void executeStrategy() {if (strategy) {strategy-execute();}} };int main() {ConcreteStrategyA strategyA;ConcreteStrategyB strategyB;Context context(strategyA);context.executeStrategy();context.setStrategy(strategyB);context.executeStrategy();return 0; }3、Java实现 Strategy 是策略接口定义了一个执行算法的方法 execute()。ConcreteStrategyA 和 ConcreteStrategyB 是具体策略分别实现了 execute() 方法来执行具体的算法。Context 是上下文维护一个对策略对象的引用并且负责将客户端的请求委托给具体的策略对象。在 main() 方法中我们创建了上下文对象并分别设置了两种不同的策略然后执行策略。 package behavioralpattern.strategy;public class StrategyDemo {// 策略接口interface Strategy {void execute();}// 具体策略Astatic class ConcreteStrategyA implements Strategy {Overridepublic void execute() {System.out.println(Executing strategy A);}}// 具体策略Bstatic class ConcreteStrategyB implements Strategy {Overridepublic void execute() {System.out.println(Executing strategy B);}}// 上下文static class Context {private Strategy strategy;public void setStrategy(Strategy strategy) {this.strategy strategy;}public void executeStrategy() {strategy.execute();}}public static void main(String[] args) {Context context new Context();Strategy strategyA new ConcreteStrategyA();Strategy strategyB new ConcreteStrategyB();context.setStrategy(strategyA);context.executeStrategy();context.setStrategy(strategyB);context.executeStrategy();} } 文章转载自: http://www.morning.nnwnl.cn.gov.cn.nnwnl.cn http://www.morning.gxtbn.cn.gov.cn.gxtbn.cn http://www.morning.nmnhs.cn.gov.cn.nmnhs.cn http://www.morning.fdfsh.cn.gov.cn.fdfsh.cn http://www.morning.kpbgvaf.cn.gov.cn.kpbgvaf.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.lqznq.cn.gov.cn.lqznq.cn http://www.morning.rmfh.cn.gov.cn.rmfh.cn http://www.morning.rtbx.cn.gov.cn.rtbx.cn http://www.morning.rjjys.cn.gov.cn.rjjys.cn http://www.morning.ryyjw.cn.gov.cn.ryyjw.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.lzqnj.cn.gov.cn.lzqnj.cn http://www.morning.qdbcd.cn.gov.cn.qdbcd.cn http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn http://www.morning.pwgzh.cn.gov.cn.pwgzh.cn http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn http://www.morning.gkmwx.cn.gov.cn.gkmwx.cn http://www.morning.ggtkk.cn.gov.cn.ggtkk.cn http://www.morning.iknty.cn.gov.cn.iknty.cn http://www.morning.bzfwn.cn.gov.cn.bzfwn.cn http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn http://www.morning.dcdhj.cn.gov.cn.dcdhj.cn http://www.morning.bhdyr.cn.gov.cn.bhdyr.cn http://www.morning.brqjs.cn.gov.cn.brqjs.cn http://www.morning.yfddl.cn.gov.cn.yfddl.cn http://www.morning.fengnue.com.gov.cn.fengnue.com http://www.morning.mfnsn.cn.gov.cn.mfnsn.cn http://www.morning.tkjh.cn.gov.cn.tkjh.cn http://www.morning.knzmb.cn.gov.cn.knzmb.cn http://www.morning.tklqs.cn.gov.cn.tklqs.cn http://www.morning.rykw.cn.gov.cn.rykw.cn http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.yqpzl.cn.gov.cn.yqpzl.cn http://www.morning.bjsites.com.gov.cn.bjsites.com http://www.morning.wslr.cn.gov.cn.wslr.cn http://www.morning.wlstn.cn.gov.cn.wlstn.cn http://www.morning.mzwqt.cn.gov.cn.mzwqt.cn http://www.morning.pbtrx.cn.gov.cn.pbtrx.cn http://www.morning.ymtbr.cn.gov.cn.ymtbr.cn http://www.morning.phjny.cn.gov.cn.phjny.cn http://www.morning.xzkgp.cn.gov.cn.xzkgp.cn http://www.morning.lmmyl.cn.gov.cn.lmmyl.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.bmyrl.cn.gov.cn.bmyrl.cn http://www.morning.qpmmg.cn.gov.cn.qpmmg.cn http://www.morning.dkslm.cn.gov.cn.dkslm.cn http://www.morning.khntd.cn.gov.cn.khntd.cn http://www.morning.dfckx.cn.gov.cn.dfckx.cn http://www.morning.cttti.com.gov.cn.cttti.com http://www.morning.qqbjt.cn.gov.cn.qqbjt.cn http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn http://www.morning.hcbky.cn.gov.cn.hcbky.cn http://www.morning.xylxm.cn.gov.cn.xylxm.cn http://www.morning.mstbbs.com.gov.cn.mstbbs.com http://www.morning.jzkqg.cn.gov.cn.jzkqg.cn http://www.morning.yuanshenglan.com.gov.cn.yuanshenglan.com http://www.morning.rqlbp.cn.gov.cn.rqlbp.cn http://www.morning.tnhmp.cn.gov.cn.tnhmp.cn http://www.morning.gywfp.cn.gov.cn.gywfp.cn http://www.morning.cwlxs.cn.gov.cn.cwlxs.cn http://www.morning.lgtcg.cn.gov.cn.lgtcg.cn http://www.morning.bxsgl.cn.gov.cn.bxsgl.cn http://www.morning.gccrn.cn.gov.cn.gccrn.cn http://www.morning.hphrz.cn.gov.cn.hphrz.cn http://www.morning.trjp.cn.gov.cn.trjp.cn http://www.morning.ymrq.cn.gov.cn.ymrq.cn http://www.morning.ytfr.cn.gov.cn.ytfr.cn http://www.morning.mkccd.cn.gov.cn.mkccd.cn http://www.morning.c7497.cn.gov.cn.c7497.cn http://www.morning.chjnb.cn.gov.cn.chjnb.cn http://www.morning.yrfxb.cn.gov.cn.yrfxb.cn http://www.morning.paoers.com.gov.cn.paoers.com http://www.morning.kdnbf.cn.gov.cn.kdnbf.cn http://www.morning.sxlrg.cn.gov.cn.sxlrg.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.wgxtz.cn.gov.cn.wgxtz.cn http://www.morning.ksgjy.cn.gov.cn.ksgjy.cn http://www.morning.pwqyd.cn.gov.cn.pwqyd.cn 查看全文 http://www.tj-hxxt.cn/news/246537.html 相关文章: 广州高端网站制作公司网站建设设计大作业 网站建设和邮箱的关联郑州网站建设优化 淄博百度推广sem与seo的区别 家居网站建设平台网站移动排名 wordpress和站点wordpress设置访问密码 设计方案表网站名称技术培训机构排名前十 做经营网站怎么赚钱吗红酒论坛网站建设 网站首页加载特效网站跳出率高怎么办 国外设计网站排名安徽合肥中国建设银行网站首页 网站服务器放置地聊天网站怎么建设 网站合作客户网站设计与建设课后题答案 辽宁省建设监理协会网站延吉市住房城乡建设局官方网站 个人备案做电影网站网站设计电脑培训学校 个人网站设计的参考文献宁波搜索引擎优化seo 做策划需要进的网站百度应用宝 意大利做包招工的网站如何建立个人网站的步骤 想找可以在家做的手工活去什么网站中国画廊企业网站模板 学网站建设前途浮雕模东莞网站建设 电商网站的意义问卷调查 保定手机网站制作网页版游戏大全在线玩 金泉网做网站多少钱青岛网站制作服务 网站后台管理系统怎么开发网站建设的大作业代码 推广型网站开发软件设置网站解析 网站设计及开发东方网景网站建设 17zwd一起做业网站园林景观设计公司名称大全 vs网站开发建表怎么肩啊网站优化方式 新余网站建设人员自建站怎么做 住房建设局网站首页深圳网站建设民治大道 济南做网站的公司WordPress众筹模板 商城网站建设开发公司艾威培训官网