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

沈阳红方城网站建设广告公司属于什么行业

沈阳红方城网站建设,广告公司属于什么行业,网站右侧二维码,wordpress 毛玻璃1、模式标准 模式名称#xff1a;策略模式 模式分类#xff1a;行为型 模式意图#xff1a;定义一系列的算法#xff0c;把它们一个个封装起来#xff0c;并且使它们可以相互替换。此模式使得算法可以独立于使用它们的客户而变化 结构图#xff1a; 适用于#xff1…1、模式标准 模式名称策略模式 模式分类行为型 模式意图定义一系列的算法把它们一个个封装起来并且使它们可以相互替换。此模式使得算法可以独立于使用它们的客户而变化 结构图 适用于 1、许多相关的类仅仅是行为有异。“策略”提供了一种用多个行为中的一个行为来配置一个类的方法。 2、需要使用一个算法的不同变体。例如定义一些反映不同空间的空间/时间权衡的算法当这些变体实现为一个算法的类层次时可以使用策略模式。 3、算法使用客户不应该知道的数据。可使用策略模式以避免暴露复杂的、与算法相关的数据结构。 4、一个类定义了多种行为,并且这些行为在这个类的操作中以多个条件语句的形式出现,将相关的条件分支移入它们各自的 Strategy 类中以代替这些条件语句。  2、分析与设计   策略和桥接模式看起来可能非常相似但策略模式是行为型桥接模式是结构型。策略模式是直接引用实现类而桥接模式是引用一个实现类的接口。当前策略模式关键是可以相互替换算法。接下来把我们曾经用过的武器替换来举例修改一下我们的意图 意图定义一系列的算法(武器)把它们一个个封装起来并且使它们可以相互替换。 3、开始打造 // 武器接口 export interface IWeapon {useWeapon(): void; }// 剑 export class Sword implements IWeapon {useWeapon(): void {console.log(用剑进行攻击);} }// 斧头 export class Axe implements IWeapon {useWeapon(): void {console.log(用斧头进行攻击);} } // 弓 export class Bow implements IWeapon {useWeapon(): void {console.log(用弓箭进行攻击);} }// 近程攻击 export class MeleeAttack implements IAttackStrategy {attack(weapon: IWeapon): void {console.log(进行近程攻击:);weapon.useWeapon();} } 【优化】结合前面的桥接模式的攻击方式我们将攻击系统升级一下 // 攻击方式接口 export interface IAttackStrategy {attack(weapon: IWeapon): void; }// 近程攻击 export class MeleeAttack implements IAttackStrategy {attack(weapon: IWeapon): void {console.log(进行近程攻击:);weapon.useWeapon();} }// 远程攻击 export class RangedAttack implements IAttackStrategy {attack(weapon: IWeapon): void {console.log(进行远程攻击:);weapon.useWeapon();} }// 武器接口 export interface IWeapon {useWeapon(): void; }// 剑 export class Sword implements IWeapon {useWeapon(): void {console.log(用剑进行攻击);} }// 斧头 export class Axe implements IWeapon {useWeapon(): void {console.log(用斧头进行攻击);} } // 弓 export class Bow implements IWeapon {useWeapon(): void {console.log(用弓箭进行攻击);} }// 抽象战斗者 export abstract class Fighter {protected attackStrategy: IAttackStrategy;protected weapon: IWeapon;constructor(attackStrategy: IAttackStrategy, weapon: IWeapon) {this.attackStrategy attackStrategy;this.weapon weapon;}attack(): void {this.attackStrategy.attack(this.weapon);}// 更换武器的方法setWeapon(weapon: IWeapon): void {this.weapon weapon;} }// 骑兵 export class Cavalry extends Fighter {constructor(attackStrategy: IAttackStrategy, weapon: IWeapon) {super(attackStrategy, weapon);} }// 弓箭手 export class Archer extends Fighter {constructor(attackStrategy: IAttackStrategy, weapon: IWeapon) {super(attackStrategy, weapon);} } 4、开始使用 export class UnitItem extends Component implements IItem, IUnitItem {ad: number 100;mp: number 0;role: Fighter;private currentState: IUnitState null;accept(visitor: IAttackVisitor) {visitor.visitUnitItem(this)}setRole(role: Fighter): void {this.role role;}setWeapon(weapon: IWeapon) {this.role.setWeapon(weapon)}..... } let unitItem001 xhgame.itemFactory.createUnitItem(kuloubing, UnitType.UnitSpine)let unitItem002 xhgame.itemFactory.createUnitItem(kuloubing, UnitType.UnitSpine)unitItem001.idle()unitItem002.idle()const sword new Sword();const bow new Bow();const axe new Axe();unitItem001.setRole(new Cavalry(new MeleeAttack(), sword));console.log(unitItem001(骑兵-近程)使用【剑】对unitItem002发起了攻击)unitItem001.attack(unitItem002)// 更换骑兵的武器为斧头unitItem001.setWeapon(axe);console.log(unitItem001(骑兵-近程)使用【斧头】对unitItem002发起了攻击)unitItem001.attack(unitItem002);unitItem002.setRole(new Cavalry(new RangedAttack(), bow));console.log(unitItem002(骑兵-远程)使用【弓】对unitItem001发起了攻击)unitItem002.attack(unitItem001) 总结桥接模式在构建时定好攻击方式策略模式在行为中使用不同的武器。
http://www.huolong8.cn/news/35647/

相关文章:

  • 网站keywords标签怎么写做电商怎么建网站
  • eclipse tomcat 网站开发网址导航被更改了怎么换回来
  • 免费s站推广网站小程序app定制
  • 自用电脑做网站公司网站开发费用济南兴田德润评价
  • 电商网站制作流程购物网站建设新闻
  • 高端手机网站建设需要多少钱关键词排名优化易下拉排名
  • 淘宝客网站设计动漫网站设计理念
  • 自己动手建设网站如何推广做引流找客源
  • 网站怎么做qq微信登陆成都 网站建设 公司
  • 网站对企业的好处四川专业网站建设
  • php企业网站开发教程网店的运营模式有哪些
  • 投资网站源码安阳市建设工程领域网站
  • 高端网站建设公司有哪些WordPress hitokoto
  • 中山网站建设 760网络技术学习网站
  • 网站开发追款单网站如何做延迟加载
  • 青岛城阳网站制作wordpress cdn ip
  • 国内知名网站建设企业平面设计找工作
  • 云南档案馆网站建设资金世界杯网站开发
  • 做编程的网站一个月多少钱深圳福田香格里拉酒店
  • 门户网站运营上海网站制作 优化
  • 南京网站制作希丁哥网页设计综合案例
  • 文山住房和城乡建设局网站扬中富裕吗
  • 做网站用什么软件当雄网站建设
  • 网站建设中端口号的作用是什么意思百度创意产品网站
  • 专门建立网站的公司吗附近人才招聘市场
  • 教做粘土的网站wordpress空间推荐
  • 云南建设厅和网站Apple 手机网站制作
  • 免费开源代码网站网站页面多大合适
  • 英文网站建设知识建网站工具
  • 做竞品分析的网站巧克力网站建设需求分析