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

编写网站的语言有哪些wordpress点击文字弹窗

编写网站的语言有哪些,wordpress点击文字弹窗,莱芜市网站建设设计,三亚论坛策略模式是一种行为设计模式#xff0c;它使你能在运行时改变对象的行为。在策略模式定义了一系列算法或策略#xff0c;并将每个算法封装在独立的类中#xff0c;使得它们可以互相替换。通过使用策略模式#xff0c;可以在运行时根据需要选择不同的算法#xff0c;而不需…策略模式是一种行为设计模式它使你能在运行时改变对象的行为。在策略模式定义了一系列算法或策略并将每个算法封装在独立的类中使得它们可以互相替换。通过使用策略模式可以在运行时根据需要选择不同的算法而不需要修改客户端代码。 主要解决的问题 解决在多种相似算法存在时使用条件语句如if…else导致的复杂性和难以维护的问题。 1. 定义策略接口 public interface IStrategy {void Execute(); }2. 实现具体策略 public class ConcreteStrategyA : IStrategy {public void Execute(){Console.WriteLine(Executing strategy A);} }public class ConcreteStrategyB : IStrategy {public void Execute(){Console.WriteLine(Executing strategy B);} }3. 上下文类 public class Context {private IStrategy _strategy;public Context(IStrategy strategy){_strategy strategy;}public void SetStrategy(IStrategy strategy){_strategy strategy;}public void ExecuteStrategy(){_strategy.Execute();} }类图 #mermaid-svg-PSWVxlB0IIxwWluB {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-PSWVxlB0IIxwWluB .error-icon{fill:#552222;}#mermaid-svg-PSWVxlB0IIxwWluB .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-PSWVxlB0IIxwWluB .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-PSWVxlB0IIxwWluB .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-PSWVxlB0IIxwWluB .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-PSWVxlB0IIxwWluB .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-PSWVxlB0IIxwWluB .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-PSWVxlB0IIxwWluB .marker{fill:#333333;stroke:#333333;}#mermaid-svg-PSWVxlB0IIxwWluB .marker.cross{stroke:#333333;}#mermaid-svg-PSWVxlB0IIxwWluB svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-PSWVxlB0IIxwWluB g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-PSWVxlB0IIxwWluB g.classGroup text .title{font-weight:bolder;}#mermaid-svg-PSWVxlB0IIxwWluB .nodeLabel,#mermaid-svg-PSWVxlB0IIxwWluB .edgeLabel{color:#131300;}#mermaid-svg-PSWVxlB0IIxwWluB .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-PSWVxlB0IIxwWluB .label text{fill:#131300;}#mermaid-svg-PSWVxlB0IIxwWluB .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-PSWVxlB0IIxwWluB .classTitle{font-weight:bolder;}#mermaid-svg-PSWVxlB0IIxwWluB .node rect,#mermaid-svg-PSWVxlB0IIxwWluB .node circle,#mermaid-svg-PSWVxlB0IIxwWluB .node ellipse,#mermaid-svg-PSWVxlB0IIxwWluB .node polygon,#mermaid-svg-PSWVxlB0IIxwWluB .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-PSWVxlB0IIxwWluB .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-PSWVxlB0IIxwWluB g.clickable{cursor:pointer;}#mermaid-svg-PSWVxlB0IIxwWluB g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-PSWVxlB0IIxwWluB g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-PSWVxlB0IIxwWluB .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-PSWVxlB0IIxwWluB .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-PSWVxlB0IIxwWluB .dashed-line{stroke-dasharray:3;}#mermaid-svg-PSWVxlB0IIxwWluB #compositionStart,#mermaid-svg-PSWVxlB0IIxwWluB .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB #compositionEnd,#mermaid-svg-PSWVxlB0IIxwWluB .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB #dependencyStart,#mermaid-svg-PSWVxlB0IIxwWluB .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB #dependencyStart,#mermaid-svg-PSWVxlB0IIxwWluB .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB #extensionStart,#mermaid-svg-PSWVxlB0IIxwWluB .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB #extensionEnd,#mermaid-svg-PSWVxlB0IIxwWluB .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB #aggregationStart,#mermaid-svg-PSWVxlB0IIxwWluB .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB #aggregationEnd,#mermaid-svg-PSWVxlB0IIxwWluB .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-PSWVxlB0IIxwWluB .edgeTerminals{font-size:11px;}#mermaid-svg-PSWVxlB0IIxwWluB :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} IStrategy void Execute() ConcreteStrategyA void Execute() ConcreteStrategyB void Execute() Context -IStrategy _strategy Context(IStrategy strategy) void SetStrategy(IStrategy strategy) void ExecuteStrategy() 用途 策略模式主要用于以下场景 • 算法变化当一个类的行为或其算法需要在运行时动态改变时。 • 多个算法变体当有多个算法变体并且需要在运行时选择其中一个时。 • 解耦将算法的定义与使用算法的客户端解耦。 优点 灵活性可以在运行时动态切换算法。扩展性增加新的策略非常容易只需实现策略接口即可。解耦策略类和上下文类之间松耦合符合开闭原则。 缺点 客户端复杂度客户端必须了解所有策略类的区别以便选择合适的策略。增加对象数量每个策略都是一个类可能会导致类的数量增加。 实际开发中的应用举例 示例1订单处理系统中的促销策略 假设一个订单处理系统需要根据不同的促销策略,比如没折扣、打折扣。也可以用是会员积分兑换来计算订单的最终价格。 1. 定义促销策略接口 public interface IPromotionStrategy {decimal ApplyPromotion(decimal originalPrice); }2. 实现具体的促销策略 public class NoDiscountStrategy : IPromotionStrategy {public decimal ApplyPromotion(decimal originalPrice){return originalPrice; // 没有折扣} }public class PercentageDiscountStrategy : IPromotionStrategy {private readonly decimal _discountPercentage;public PercentageDiscountStrategy(decimal discountPercentage){_discountPercentage discountPercentage;}public decimal ApplyPromotion(decimal originalPrice){return originalPrice * (1 - _discountPercentage / 100);//折扣} }public class FixedAmountDiscountStrategy : IPromotionStrategy {private readonly decimal _discountAmount;public FixedAmountDiscountStrategy(decimal discountAmount){_discountAmount discountAmount;}public decimal ApplyPromotion(decimal originalPrice){return originalPrice - _discountAmount;} }3. 上下文类 public class Order {private IPromotionStrategy _promotionStrategy;private decimal _originalPrice;public Order(decimal originalPrice, IPromotionStrategy promotionStrategy){_originalPrice originalPrice;_promotionStrategy promotionStrategy;}public void SetPromotionStrategy(IPromotionStrategy promotionStrategy){_promotionStrategy promotionStrategy;}public decimal CalculateFinalPrice(){return _promotionStrategy.ApplyPromotion(_originalPrice);} }4. 使用示例 class Program {static void Main(string[] args){// 创建订单初始价格为100元没有折扣var order new Order(100, new NoDiscountStrategy());Console.WriteLine($Original price: {order.CalculateFinalPrice()});// 应用百分比折扣策略折扣10%order.SetPromotionStrategy(new PercentageDiscountStrategy(10));Console.WriteLine($Price after 10% discount: {order.CalculateFinalPrice()});// 应用固定金额折扣策略折扣20元order.SetPromotionStrategy(new FixedAmountDiscountStrategy(20));Console.WriteLine($Price after fixed 20 discount: {order.CalculateFinalPrice()});} }类图 #mermaid-svg-gmDVPXzMlpfk7zIU {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-gmDVPXzMlpfk7zIU .error-icon{fill:#552222;}#mermaid-svg-gmDVPXzMlpfk7zIU .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-gmDVPXzMlpfk7zIU .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-gmDVPXzMlpfk7zIU .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-gmDVPXzMlpfk7zIU .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-gmDVPXzMlpfk7zIU .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-gmDVPXzMlpfk7zIU .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-gmDVPXzMlpfk7zIU .marker{fill:#333333;stroke:#333333;}#mermaid-svg-gmDVPXzMlpfk7zIU .marker.cross{stroke:#333333;}#mermaid-svg-gmDVPXzMlpfk7zIU svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-gmDVPXzMlpfk7zIU g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-gmDVPXzMlpfk7zIU g.classGroup text .title{font-weight:bolder;}#mermaid-svg-gmDVPXzMlpfk7zIU .nodeLabel,#mermaid-svg-gmDVPXzMlpfk7zIU .edgeLabel{color:#131300;}#mermaid-svg-gmDVPXzMlpfk7zIU .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-gmDVPXzMlpfk7zIU .label text{fill:#131300;}#mermaid-svg-gmDVPXzMlpfk7zIU .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-gmDVPXzMlpfk7zIU .classTitle{font-weight:bolder;}#mermaid-svg-gmDVPXzMlpfk7zIU .node rect,#mermaid-svg-gmDVPXzMlpfk7zIU .node circle,#mermaid-svg-gmDVPXzMlpfk7zIU .node ellipse,#mermaid-svg-gmDVPXzMlpfk7zIU .node polygon,#mermaid-svg-gmDVPXzMlpfk7zIU .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-gmDVPXzMlpfk7zIU .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-gmDVPXzMlpfk7zIU g.clickable{cursor:pointer;}#mermaid-svg-gmDVPXzMlpfk7zIU g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-gmDVPXzMlpfk7zIU g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-gmDVPXzMlpfk7zIU .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-gmDVPXzMlpfk7zIU .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-gmDVPXzMlpfk7zIU .dashed-line{stroke-dasharray:3;}#mermaid-svg-gmDVPXzMlpfk7zIU #compositionStart,#mermaid-svg-gmDVPXzMlpfk7zIU .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU #compositionEnd,#mermaid-svg-gmDVPXzMlpfk7zIU .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU #dependencyStart,#mermaid-svg-gmDVPXzMlpfk7zIU .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU #dependencyStart,#mermaid-svg-gmDVPXzMlpfk7zIU .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU #extensionStart,#mermaid-svg-gmDVPXzMlpfk7zIU .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU #extensionEnd,#mermaid-svg-gmDVPXzMlpfk7zIU .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU #aggregationStart,#mermaid-svg-gmDVPXzMlpfk7zIU .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU #aggregationEnd,#mermaid-svg-gmDVPXzMlpfk7zIU .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-gmDVPXzMlpfk7zIU .edgeTerminals{font-size:11px;}#mermaid-svg-gmDVPXzMlpfk7zIU :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} IPromotionStrategy decimal ApplyPromotion(decimal originalPrice) NoDiscountStrategy decimal ApplyPromotion(decimal originalPrice) PercentageDiscountStrategy -decimal _discountPercentage PercentageDiscountStrategy(decimal discountPercentage) decimal ApplyPromotion(decimal originalPrice) FixedAmountDiscountStrategy -decimal _discountAmount FixedAmountDiscountStrategy(decimal discountAmount) decimal ApplyPromotion(decimal originalPrice) Order -IPromotionStrategy _promotionStrategy -decimal _originalPrice Order(decimal originalPrice, IPromotionStrategy promotionStrategy) void SetPromotionStrategy(IPromotionStrategy promotionStrategy) decimal CalculateFinalPrice() 解释 定义促销策略接口IPromotionStrategy 接口定义了一个 ApplyPromotion 方法用于计算应用促销后的价格。实现具体的促销策略 • NoDiscountStrategy不应用任何折扣。 • PercentageDiscountStrategy应用百分比折扣。 • FixedAmountDiscountStrategy应用固定金额折扣。上下文类Order 类包含一个促销策略并提供方法来设置促销策略和计算最终价格。使用示例创建一个订单初始价格为100元然后依次应用不同的促销策略输出最终价格。 示例2物流管理系统中的运输策略 假设一个物流管理系统需要根据不同的运输方式如快递、货运、空运等来计算运费。也可以使用策略模式来实现这一点。 1. 定义运输策略接口 public interface ITransportStrategy {decimal CalculateShippingCost(decimal weight, decimal distance); }2. 实现具体的运输策略 public class ExpressShippingStrategy : ITransportStrategy {public decimal CalculateShippingCost(decimal weight, decimal distance){// 快递费用计算公式重量 * 距离 * 0.5return weight * distance * 0.5m;} }public class FreightShippingStrategy : ITransportStrategy {public decimal CalculateShippingCost(decimal weight, decimal distance){// 货运费用计算公式重量 * 距离 * 0.3return weight * distance * 0.3m;} }public class AirShippingStrategy : ITransportStrategy {public decimal CalculateShippingCost(decimal weight, decimal distance){// 空运费用计算公式重量 * 距离 * 1.0return weight * distance * 1.0m;} }3. 上下文类 public class Shipment {private ITransportStrategy _transportStrategy;private decimal _weight;private decimal _distance;public Shipment(decimal weight, decimal distance, ITransportStrategy transportStrategy){_weight weight;_distance distance;_transportStrategy transportStrategy;}public void SetTransportStrategy(ITransportStrategy transportStrategy){_transportStrategy transportStrategy;}public decimal CalculateTotalCost(){return _transportStrategy.CalculateShippingCost(_weight, _distance);} }4. 使用示例 class Program {static void Main(string[] args){// 创建一个货物重量为100公斤距离为500公里使用快递运输var shipment new Shipment(100, 500, new ExpressShippingStrategy());Console.WriteLine($Express Shipping Cost: {shipment.CalculateTotalCost()});// 更改为货运运输shipment.SetTransportStrategy(new FreightShippingStrategy());Console.WriteLine($Freight Shipping Cost: {shipment.CalculateTotalCost()});// 更改为空运运输shipment.SetTransportStrategy(new AirShippingStrategy());Console.WriteLine($Air Shipping Cost: {shipment.CalculateTotalCost()});} }类图 #mermaid-svg-lw6M71ICaHMpgc3r {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-lw6M71ICaHMpgc3r .error-icon{fill:#552222;}#mermaid-svg-lw6M71ICaHMpgc3r .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-lw6M71ICaHMpgc3r .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-lw6M71ICaHMpgc3r .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-lw6M71ICaHMpgc3r .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-lw6M71ICaHMpgc3r .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-lw6M71ICaHMpgc3r .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-lw6M71ICaHMpgc3r .marker{fill:#333333;stroke:#333333;}#mermaid-svg-lw6M71ICaHMpgc3r .marker.cross{stroke:#333333;}#mermaid-svg-lw6M71ICaHMpgc3r svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-lw6M71ICaHMpgc3r g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-lw6M71ICaHMpgc3r g.classGroup text .title{font-weight:bolder;}#mermaid-svg-lw6M71ICaHMpgc3r .nodeLabel,#mermaid-svg-lw6M71ICaHMpgc3r .edgeLabel{color:#131300;}#mermaid-svg-lw6M71ICaHMpgc3r .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-lw6M71ICaHMpgc3r .label text{fill:#131300;}#mermaid-svg-lw6M71ICaHMpgc3r .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-lw6M71ICaHMpgc3r .classTitle{font-weight:bolder;}#mermaid-svg-lw6M71ICaHMpgc3r .node rect,#mermaid-svg-lw6M71ICaHMpgc3r .node circle,#mermaid-svg-lw6M71ICaHMpgc3r .node ellipse,#mermaid-svg-lw6M71ICaHMpgc3r .node polygon,#mermaid-svg-lw6M71ICaHMpgc3r .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-lw6M71ICaHMpgc3r .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-lw6M71ICaHMpgc3r g.clickable{cursor:pointer;}#mermaid-svg-lw6M71ICaHMpgc3r g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-lw6M71ICaHMpgc3r g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-lw6M71ICaHMpgc3r .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-lw6M71ICaHMpgc3r .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-lw6M71ICaHMpgc3r .dashed-line{stroke-dasharray:3;}#mermaid-svg-lw6M71ICaHMpgc3r #compositionStart,#mermaid-svg-lw6M71ICaHMpgc3r .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r #compositionEnd,#mermaid-svg-lw6M71ICaHMpgc3r .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r #dependencyStart,#mermaid-svg-lw6M71ICaHMpgc3r .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r #dependencyStart,#mermaid-svg-lw6M71ICaHMpgc3r .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r #extensionStart,#mermaid-svg-lw6M71ICaHMpgc3r .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r #extensionEnd,#mermaid-svg-lw6M71ICaHMpgc3r .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r #aggregationStart,#mermaid-svg-lw6M71ICaHMpgc3r .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r #aggregationEnd,#mermaid-svg-lw6M71ICaHMpgc3r .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-lw6M71ICaHMpgc3r .edgeTerminals{font-size:11px;}#mermaid-svg-lw6M71ICaHMpgc3r :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} ITransportStrategy decimal CalculateShippingCost(decimal weight, decimal distance) ExpressShippingStrategy decimal CalculateShippingCost(decimal weight, decimal distance) FreightShippingStrategy decimal CalculateShippingCost(decimal weight, decimal distance) AirShippingStrategy decimal CalculateShippingCost(decimal weight, decimal distance) Shipment -ITransportStrategy _transportStrategy -decimal _weight -decimal _distance Shipment(decimal weight, decimal distance, ITransportStrategy transportStrategy) void SetTransportStrategy(ITransportStrategy transportStrategy) decimal CalculateTotalCost() 解释 定义运输策略接口ITransportStrategy 接口定义了一个 CalculateShippingCost 方法用于计算运输费用。实现具体的运输策略 • ExpressShippingStrategy快递运输费用计算。 • FreightShippingStrategy货运运输费用计算。 • AirShippingStrategy空运运输费用计算。上下文类Shipment 类包含一个运输策略并提供方法来设置运输策略和计算总费用。使用示例创建一个货物初始运输方式为快递然后依次更改为货运和空运输出每种运输方式的费用。 优点 灵活性可以在运行时动态切换促销策略。扩展性增加新的促销策略非常容易只需实现 IPromotionStrategy 接口即可。解耦订单类和促销策略类之间松耦合符合开闭原则。 缺点 客户端复杂度客户端必须了解所有促销策略的区别以便选择合适的策略。增加对象数量每个促销策略都是一个类可能会导致类的数量增加。
http://www.hkea.cn/news/14516834/

相关文章:

  • 商务咨询公司网站制作模板ysl网站设计论文
  • 免费网站重生做军嫂哪个app推广佣金高
  • 做外汇哪个网站看外国消息温州高端网站建设公司
  • 网站开发报告样式wordpress写文章排版
  • 如何租用网站服务器国外广告设计网站
  • 秦皇岛的网站建设公司外贸网站搭建难不难
  • wordpress图片文件目录下网站长尾关键词优化
  • 沈阳做网站找思路动漫项网站建设项目项目建议书
  • 网站建设需要怎样的经营范围网站开发时app打开很慢
  • 乡镇网站建设和培训设计理论网站
  • 网站下拉框怎么做找地推平台
  • 企业网站开发是什么做网站如何文字链接文字
  • 免费网站制作开发三明市住房与建设局网站
  • 容县网站建设济南腾飞网络网站建设
  • 企业建网站群网站怎么做图片放映效果
  • wordpress移动新闻seo中文
  • 工厂的网站在哪里做的宝塔网站建设跳转微信可打开
  • 三亚做网站哪家效果好wordpress评论框加
  • 技术支持 东莞网站建设舞蹈培训建设工程质量安全管理协会网站
  • 信息发布网站怎么做旅游响应式网站建设
  • 布吉网站建设哪家服务周到做照片模板下载网站
  • 去哪找网站建设公司好rt19 wordpress
  • 什么是网站网页主页百度云引擎搜索
  • 西安哪些做网站的公司好制作企业网站页面代码摄影 开课吧
  • 网站开发 php网页版ps
  • 易企建站云点wordpress
  • 哪个网站教做饭做的好凉山州建设网站
  • 抚顺网站网站建设网络营销是什么基础
  • 做网站网页的工作怎么样wordpress主题不一样
  • 国外做微课的网站网站建设成都公司哪家好