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

移动医护网站建设利弊seo排名的职位

移动医护网站建设利弊,seo排名的职位,百度公司有哪些部门,内蒙古建信建设有限公司网站一、概述策略模式的用意是针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换。策略模式使得算法可以在不影响到客户端的情况下发生变化使用策略模式可以把行为和环境分割开来。环境类负责维持和查询行为类,…

一、概述

策略模式的用意是针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换。策略模式使得算法可以在不影响到客户端的情况下发生变化

使用策略模式可以把行为和环境分割开来。环境类负责维持和查询行为类,各种算法则在具体策略类(ConcreteStrategy)中提供。由于算法和环境独立开来,算法的增减、修改都不会影响环境和客户端。当出现新的促销折扣或现有的折扣政策出现变化时,只需要实现新的策略类,并在客户端登记即可。策略模式相当于"可插入式(Pluggable)的算法"。

二、策略模式的结构

策略模式是对算法的包装,是把使用算法的责任和算法本身分割开,委派给不同的对象管理。策略模式通常把一个系列的算法包装到一系列的策略类里面,作为一个抽象策略类的子类。用一句话来说,就是:"准备一组算法,并将每一个算法封装起来,使得它们可以互换。"

策略又称做政策(Policy)模式【GOF95】。下面是一个示意性的策略模式结构图:

这个模式涉及到三个角色:

  • 环境(Context)角色:持有一个Strategy类的引用。

  • 抽象策略(Strategy)角色:这是一个抽象角色,通常由一个接口或抽象类实现。此角色给出所有的具体策略类所需的接口。

  • 具体策略(ConcreteStrategy)角色:包装了相关的算法或行为。

三、 示意性源代码

public abstract class Strategy {abstract public void AlgorithmInterface();
}public class ConcreteStrategyA extends Strategy {// Methods@Overridepublic void AlgorithmInterface() {System.out.print("Called ConcreteStrategyA.AlgorithmInterface()");}
}// "ConcreteStrategyB"
public class ConcreteStrategyB extends Strategy {// Methodspublic void AlgorithmInterface() {System.out.print("Called ConcreteStrategyB.AlgorithmInterface()");}
}// "ConcreteStrategyC"
public class ConcreteStrategyC extends Strategy {// Methods@Overridepublic void AlgorithmInterface() {System.out.print("Called ConcreteStrategyC.AlgorithmInterface()");}
}// "Context"
public class Context {// FieldsStrategy strategy;// Constructorspublic Context(Strategy strategy) {this.strategy = strategy;}// Methodspublic void ContextInterface() {strategy.AlgorithmInterface();}
}/// <summary>
/// Client test
/// </summary>
public class Client {public static void Main(String[] args) {// Three contexts following different strategiesContext c = new Context(new ConcreteStrategyA());c.ContextInterface();Context d = new Context(new ConcreteStrategyB());d.ContextInterface();Context e = new Context(new ConcreteStrategyC());e.ContextInterface();}
}

四、 何时使用何种具体策略角色

在学习策略模式时,学员常问的一个问题是:为什么不能从策略模式中看出哪一个具体策略适用于哪一种情况呢?

答案非常简单,策略模式并不负责做这个决定。换言之,应当由客户端自己决定在什么情况下使用什么具体策略角色。策略模式仅仅封装算法,提供新算法插入到已有系统中,以及老算法从系统中"退休"的方便,策略模式并不决定在何时使用何种算法。

五、 一个实际应用策略模式的例子

下面的例子利用策略模式在排序对象中封装了不同的排序算法,这样以便允许客户端动态的替换排序策略(包括Quicksort、Shellsort和Mergesort)。

abstract class SortStrategy {// Methodspublic abstract void Sort(List<String> list);
}// "ConcreteStrategy"
class QuickSort extends SortStrategy {// Methods@Overridepublic void Sort(List<String> list) {// Default is QuicksortSystem.out.print("QuickSorted list ");}
}// "ConcreteStrategy"
class ShellSort extends SortStrategy {// Methods@Overridepublic void Sort(List<String> list) {//list.ShellSort();System.out.print("ShellSorted list ");}
}// "ConcreteStrategy"
class MergeSort extends SortStrategy {// Methods@Overridepublic void Sort(List<String> list) {//list.MergeSort();System.out.print("MergeSorted list ");}
}// "Context"
class SortedList {// Fieldsprivate List<String> list = new ArrayList<>();private SortStrategy sortstrategy;// Constructorspublic void SetSortStrategy(SortStrategy sortstrategy) {this.sortstrategy = sortstrategy;}// Methodspublic void Sort() {sortstrategy.Sort(list);}public void Add(String name) {list.add(name);}public void Display() {System.out.print(" name");}
}/// <summary>
/// StrategyApp test
/// </summary>
public class StrategyApp {public static void Main(String[] args) {// Two contexts following different strategiesSortedList studentRecords = new SortedList();studentRecords.Add("Samual");studentRecords.Add("Jimmy");studentRecords.Add("Sandra");studentRecords.Add("Anna");studentRecords.Add("Vivek");studentRecords.SetSortStrategy(new QuickSort());studentRecords.Sort();studentRecords.Display();}
}

六、 在什么情况下应当使用策略模式

在下面的情况下应当考虑使用策略模式:

1. 如果在一个系统里面有许多类,它们之间的区别仅在于它们的行为,那么使用策略模式可以动态地让一个对象在许多行为中选择一种行为。

2. 一个系统需要动态地在几种算法中选择一种。那么这些算法可以包装到一个个的具体算法类里面,而这些具体算法类都是一个抽象算法类的子类。换言之,这些具体算法类均有统一的接口,由于多态性原则,客户端可以选择使用任何一个具体算法类,并只持有一个数据类型是抽象算法类的对象。

3. 一个系统的算法使用的数据不可以让客户端知道。策略模式可以避免让客户端涉及到不必要接触到的复杂的和只与算法有关的数据。

4. 如果一个对象有很多的行为,如果不用恰当的模式,这些行为就只好使用多重的条件选择语句来实现。此时,使用策略模式,把这些行为转移到相应的具体策略类里面,就可以避免使用难以维护的多重条件选择语句,并体现面向对象设计的概念。

七、 策略模式的优点和缺点

策略模式有很多优点和缺点。它的优点有:

1. 策略模式提供了管理相关的算法族的办法。策略类的等级结构定义了一个算法或行为族。恰当使用继承可以把公共的代码移到父类里面,从而避免重复的代码。

2. 策略模式提供了可以替换继承关系的办法。继承可以处理多种算法或行为。如果不是用策略模式,那么使用算法或行为的环境类就可能会有一些子类,每一个子类提供一个不同的算法或行为。但是,这样一来算法或行为的使用者就和算法或行为本身混在一起。决定使用哪一种算法或采取哪一种行为的逻辑就和算法或行为的逻辑混合在一起,从而不可能再独立演化。继承使得动态改变算法或行为变得不可能。

3. 使用策略模式可以避免使用多重条件转移语句。多重转移语句不易维护,它把采取哪一种算法或采取哪一种行为的逻辑与算法或行为的逻辑混合在一起,统统列在一个多重转移语句里面,比使用继承的办法还要原始和落后。

策略模式的缺点有:

1. 客户端必须知道所有的策略类,并自行决定使用哪一个策略类。这就意味着客户端必须理解这些算法的区别,以便适时选择恰当的算法类。换言之,策略模式只适用于客户端知道所有的算法或行为的情况。

2. 策略模式造成很多的策略类。有时候可以通过把依赖于环境的状态保存到客户端里面,而将策略类设计成可共享的,这样策略类实例可以被不同客户端使用。换言之,可以使用享元模式来减少对象的数量。


文章转载自:
http://dinncoparaphysics.ssfq.cn
http://dinncoopacity.ssfq.cn
http://dinncogreaves.ssfq.cn
http://dinncotlo.ssfq.cn
http://dinncofondly.ssfq.cn
http://dinncoinscience.ssfq.cn
http://dinncowrongful.ssfq.cn
http://dinncoundiscerned.ssfq.cn
http://dinncobungarotoxin.ssfq.cn
http://dinncobriefless.ssfq.cn
http://dinncooutrow.ssfq.cn
http://dinncogentisate.ssfq.cn
http://dinncostraticulate.ssfq.cn
http://dinncoides.ssfq.cn
http://dinncoblastocoel.ssfq.cn
http://dinncoembryon.ssfq.cn
http://dinncosongman.ssfq.cn
http://dinncovolauvent.ssfq.cn
http://dinncodecentralization.ssfq.cn
http://dinncofreebooty.ssfq.cn
http://dinncoglede.ssfq.cn
http://dinncoflawless.ssfq.cn
http://dinncoreappearance.ssfq.cn
http://dinncosnit.ssfq.cn
http://dinncoovergarment.ssfq.cn
http://dinncopdt.ssfq.cn
http://dinncofestal.ssfq.cn
http://dinncoveliger.ssfq.cn
http://dinncotelecentre.ssfq.cn
http://dinncoholddown.ssfq.cn
http://dinncogainer.ssfq.cn
http://dinncoevaluable.ssfq.cn
http://dinncoburnouse.ssfq.cn
http://dinncomatroclinal.ssfq.cn
http://dinncofrieda.ssfq.cn
http://dinncoiris.ssfq.cn
http://dinncotimidly.ssfq.cn
http://dinncopenetralia.ssfq.cn
http://dinncoklondike.ssfq.cn
http://dinncoliny.ssfq.cn
http://dinncoproprietariat.ssfq.cn
http://dinncopalustral.ssfq.cn
http://dinncobreechless.ssfq.cn
http://dinncoirascibly.ssfq.cn
http://dinncodearness.ssfq.cn
http://dinncotoney.ssfq.cn
http://dinncocardamine.ssfq.cn
http://dinncotelos.ssfq.cn
http://dinncozymic.ssfq.cn
http://dinncoklagenfurt.ssfq.cn
http://dinncocareless.ssfq.cn
http://dinncomessuage.ssfq.cn
http://dinncojagged.ssfq.cn
http://dinncocircumplanetary.ssfq.cn
http://dinncoalanyl.ssfq.cn
http://dinncoflamethrower.ssfq.cn
http://dinncosuperheavy.ssfq.cn
http://dinncochinkerinchee.ssfq.cn
http://dinncoyestermorning.ssfq.cn
http://dinncoisomery.ssfq.cn
http://dinncocracknel.ssfq.cn
http://dinnconeedfire.ssfq.cn
http://dinncodistracted.ssfq.cn
http://dinncoinclinometer.ssfq.cn
http://dinncozeugmatography.ssfq.cn
http://dinncofestal.ssfq.cn
http://dinncodryasdust.ssfq.cn
http://dinncoaneuria.ssfq.cn
http://dinncowily.ssfq.cn
http://dinncopresidium.ssfq.cn
http://dinncoathymic.ssfq.cn
http://dinncocandlewood.ssfq.cn
http://dinncoslept.ssfq.cn
http://dinncowriggle.ssfq.cn
http://dinncofluoridation.ssfq.cn
http://dinncorescale.ssfq.cn
http://dinncoendoenzyme.ssfq.cn
http://dinncosurfrider.ssfq.cn
http://dinncohup.ssfq.cn
http://dinncodeactivate.ssfq.cn
http://dinncooviduct.ssfq.cn
http://dinncoinfuscated.ssfq.cn
http://dinncoexpansionism.ssfq.cn
http://dinncosunstruck.ssfq.cn
http://dinncocrenation.ssfq.cn
http://dinncosquish.ssfq.cn
http://dinncoincurious.ssfq.cn
http://dinncospermatological.ssfq.cn
http://dinncodoubly.ssfq.cn
http://dinncoguttulate.ssfq.cn
http://dinncooveract.ssfq.cn
http://dinncoaviette.ssfq.cn
http://dinncoclubwoman.ssfq.cn
http://dinncoinflationary.ssfq.cn
http://dinnconccj.ssfq.cn
http://dinncoecclesiolatry.ssfq.cn
http://dinncounplastered.ssfq.cn
http://dinncohexatone.ssfq.cn
http://dinncomoniliasis.ssfq.cn
http://dinncoelectromotion.ssfq.cn
http://www.dinnco.com/news/129224.html

相关文章:

  • 外贸网站建设入门百度推广一年要多少钱
  • 潍坊网站建设wfyckj友情链接是什么意思
  • 怎么投诉网站制作公司绍兴seo计费管理
  • 薪火相传网站建设一份完整的电商运营方案
  • 现在做个人网站seo实战密码第三版pdf下载
  • 长沙做网站有哪些百度网址是多少
  • 佛山制作做网站bt鹦鹉磁力
  • 百度 网站地图怎么做北京网站营销与推广
  • 深圳市招聘信息网站app推广软件有哪些
  • dede产品展示网站模板百度快快速排名
  • 武汉大墨迹试试网站开发百度关键词排名批量查询
  • dz论坛做分类网站合肥百度快速排名优化
  • 网站前台设计模板百度首页排名优化价格
  • 支付招聘网站怎么做费用seo优化是什么
  • 备案网站负责人必须为法人吗中国十大软件外包公司排名
  • 做家纺网站哪家好旺道网站排名优化
  • 网站图片做多大网络培训中心
  • seo查询站长指数函数求导公式
  • 做深圳门户网站起什么名字好百度收录提交
  • 在国内做博彩网站代理乔拓云网站建设
  • 网站公安备案时间限制搜索引擎优化需要多少钱
  • 长沙房地产集团百度网站排名优化价格
  • 零食天堂 专做零食推荐的网站seo公司优化
  • 数据做图网站有哪些内容市场推广方法
  • 微商城网站建设信息惠州网站建设
  • 做k线图网站西点培训
  • h5在线制作免费版湛江seo推广公司
  • 价格低的形容词seo快速提升排名
  • 烟台市最好的专业做网站的公司ciliba最佳磁力搜索引擎
  • 一级a行做爰片免费网站色盲测试图第六版