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

去哪个网站有客户找做标书的2023年10月疫情还会严重吗

去哪个网站有客户找做标书的,2023年10月疫情还会严重吗,山东网站建设找哪家,网站建设 学习 长沙阅读建议 嗨,伙计!刷到这篇文章咱们就是有缘人,在阅读这篇文章前我有一些建议: 本篇文章大概4000多字,阅读时间长可能需要4-5分钟,请结合示例耐心读完,绝对有收获。设计模式属于程序的设计思…

阅读建议 


嗨,伙计!刷到这篇文章咱们就是有缘人,在阅读这篇文章前我有一些建议:

  1. 本篇文章大概4000多字,阅读时间长可能需要4-5分钟,请结合示例耐心读完,绝对有收获。
  2. 设计模式属于程序的设计思想、方法类的内容,阅读一遍,在理解上不一定会很透彻,建议收藏起来,有空多看看,书读百遍,其义自现。
  3. 创作不易,免费的点赞、关注,请走上一走,也算是对博主一些鼓励,可以让我更有动力输出更多的干货内容。
  4. UML类图是一个好东西,要多看,如果会画,就更好了,一图胜千言。

什么是命令模式

        命令模式(Command Pattern)是一种行为型设计模式,它将请求和处理分开,使得请求发送者和接收者解耦,从而降低系统的耦合度。在命令模式中,请求被封装为一个独立的对象,并且将其参数化,以便在不同的请求中传递不同的参数。

命令模式有哪些核心角色

        在命令模式中,请求被封装为一个对象,从而可以将请求的调用者与实现者分离开来。这降低了系统的耦合度,使得不同的调用者可以发送不同的请求给同一个接收者,而不需要修改接收者的代码。同时,命令模式还提供了对事务进行建模的方法,可以实现对事务的撤销、重做等操作。其核心角色主要有以下几个核心组成部分:

  1. 命令接口(Command):定义了执行操作的接口,通常包含一个执行方法(execute)。
  2. 具体命令(ConcreteCommand):实现了命令接口,持有对一个接收者对象的引用,并将请求转发给接收者执行具体的操作。
  3. 接收者(Receiver):负责具体执行命令所指定的操作。
  4. 调用者(Invoker):持有一个命令对象,负责调用命令对象执行请求。
  5. 客户端(Client):创建具体的命令对象,并设置命令的接收者。

        通过命令模式,客户端与调用者之间的耦合可以被解耦,客户端只需创建具体的命令对象并将其传递给调用者,而不需要了解具体的接收者和操作细节。这样可以实现请求的发送者和接收者之间的解耦,并且支持对请求进行排队、记录日志、撤销和重做等操作。

命令模式如何实现

需求描述

        理解了命令模式的定义、核心角色以及各核心角色的功能作用,如何实现就变得很简单,下面以生活中一个事情为例来说明一下如何实现命令模式。在生活中,下班回家后,坐在沙发上用遥控器打开电视是一个很常见的事情。如果写一段程序来实现用遥控器打开电视这个过程,使用命令模式就是一个很好的选择。遥控器本身就是一个命令的接收者,而打开电视这个动作实现上就是一个指令。

实现方法

        1、声明一个实体电视的遥控器类,也就是具体的指令接收者;

/*** 遥控器*/
public class RemoteControl {public void onGreenButton(){System.out.println("打开电视");}public void onRedButton(){System.out.println("关闭电视");}public void onButton2_1(){System.out.println("河南卫视");}public void onButton2_2(){System.out.println("北京卫视");}public void onButton2_3(){System.out.println("山东卫视");}public void onDefaultButton(){System.out.println("中央电视台");}
}

        2、声明一个抽象指令接口,在其中定义一个抽象指令执行内容方法,供具体的指令类去实现;

/*** 抽象命令接口*/
public interface Command {void execute();
}

        3、声明具体按钮指令,实现于抽象接口中,重写抽象方法的具体实现,如打开电视、关闭电视;

/*** 打开指令*/
public class OpenCommand implements Command{private RemoteControl remoteControl;public OpenCommand(RemoteControl remoteControl) {this.remoteControl = remoteControl;}@Overridepublic void execute() {this.remoteControl.onGreenButton();}
}
/*** 关闭指令*/
public class CloseCommand implements Command {private RemoteControl remoteControl;public CloseCommand(RemoteControl remoteControl) {this.remoteControl = remoteControl;}@Overridepublic void execute() {this.remoteControl.onRedButton();}
}

        4、声明一个指令调用者,持有一个具体的指令对象,即遥控器上具体的按钮指令;

/*** 命令执行器*/
public class CommandInvoker {private Command command;public CommandInvoker(Command command) {this.command = command;}public void executeCommand(){this.command.execute();}
}

        5、编写客户端,将具体的遥控器对象、具体的指令整合在一起,执行具体的业务操作;

public class Client {public static void main(String[] args) {RemoteControl remoteControl = new RemoteControl();Command command=new OpenCommand(remoteControl);CommandInvoker commandInvoker = new CommandInvoker(command);commandInvoker.executeCommand();command=new CloseCommand(remoteControl);commandInvoker=new CommandInvoker(command);command.executeCommand();}
}

如何扩展

        相信现在大家都了解这样一个事实:现在的电视机真是相当的难用,广告多的不行,各种套娃式的收费,但是我观察到一个也比较恶心的现象,现在遥控器上面的数字按钮没有了,看上去很简洁,实际上使用体验并不好。那么如果把这些数字按钮再加上去,我想看哪个电视台直接就按哪个,岂不妙哉?在命令模式的基础上来扩展类似的需求非常简单:

        1、增加数字按钮指令;

/*** 数字指令*/
public class NumberCommand implements Command{private int number;private RemoteControl remoteControl;public NumberCommand(RemoteControl remoteControl) {this.remoteControl = remoteControl;}public void setNumber(int number) {this.number = number;}@Overridepublic void execute() {switch (number){case 21:this.remoteControl.onButton2_1();break;case 22:this.remoteControl.onButton2_2();break;case 23:this.remoteControl.onButton2_3();break;default:this.remoteControl.onDefaultButton();break;}}
}

        2、升级一下原来的遥控器的相关业务即可,原先的其他指令按钮,如打指令按钮、关闭指令按钮等,不用变化;

public class Client {public static void main(String[] args) {RemoteControl remoteControl = new RemoteControl();Command  command=new NumberCommand(remoteControl);CommandInvoker commandInvoker=new CommandInvoker(command);commandInvoker.executeCommand();((NumberCommand) command).setNumber(21);commandInvoker.executeCommand();((NumberCommand) command).setNumber(22);commandInvoker.executeCommand();}
}

命令模式适用哪些场景

        具有以下特征的业务场景,都是比较适合使用命令行模式的,如:

  1. 请求发送者和接收者需要解耦:命令模式允许发送者和接收者之间没有直接的关系,二者通过命令进行交互。发送者只需要知道发送请求对象,不需要知道如何完成请求;接收者只需要知道如何完成请求,不需要知道请求的发送过程。这种解耦方式可以使系统更加灵活和可维护。
  2. 需要抽象出待执行的行为:命令模式可以将等待执行的行为抽象出来,将命令封装成对象,以便在程序中灵活地操作。这种抽象方式可以方便地对命令进行记录、撤销、重做等操作。

命令模式的优点和缺点

优点

  1. 解耦:命令模式解耦了请求发送者和接收者之间的耦合关系,使得发送者和接收者只需要通过命令对象进行交互,而不需要直接联系。
  2. 抽象:命令模式将请求或操作封装成命令对象,从而抽象出待执行的行为,提高了系统的可维护性和可扩展性。
  3. 事务支持:命令模式支持事务操作,可以将多个命令组合成一个事务,从而保证操作的原子性和一致性。
  4. 撤销支持:命令模式可以方便地支持撤销操作,通过实现命令的撤销功能,可以轻松地回滚操作,提高系统的可靠性和可维护性。
  5. 日志记录:命令模式可以实现日志记录功能,将命令的操作记录下来,以便后续的审计和调试。
  6. 宏命令:命令模式可以支持宏命令,将多个命令组合成一个宏命令,一次性执行多个操作。

缺点

  1. 具体命令类可能过多:在命令模式中,每个不同的请求或操作都需要一个具体的命令类来封装。因此,如果有很多不同的请求或操作,就需要定义很多具体的命令类,这会增加系统的复杂度和维护成本。
  2. 实现复杂度较高:命令模式需要定义很多类和接口,同时需要实现撤销、事务、日志记录等功能,因此实现起来比较复杂。
  3. 设计难度较大:命令模式需要设计出合适的命令类和接收者类,以及它们之间的交互关系和行为定义等,这需要具备较高的设计能力和经验。

总结

        命令模式是一种行为型设计模式,它允许将请求或操作封装成对象,从而解耦了请求发送者和接收者之间的耦合关系,具有解耦、抽象、事务支持、撤销支持、日志记录和宏命令等优点,但也存在具体命令类过多、实现复杂度高和设计难度大等缺点。在使用命令模式时,需要根据具体的应用场景和需求来权衡其优劣。

        总之,命令模式是一种非常实用的设计模式,它可以提高系统的灵活性和可维护性,使得代码更加清晰、易于理解和扩展,强烈建议在合适的场景中使用它。


文章转载自:
http://dinncoviatic.stkw.cn
http://dinncocaribbean.stkw.cn
http://dinncoherder.stkw.cn
http://dinncocobber.stkw.cn
http://dinncofrena.stkw.cn
http://dinncorivalship.stkw.cn
http://dinncodeflationist.stkw.cn
http://dinncosalicylamide.stkw.cn
http://dinncocaseate.stkw.cn
http://dinncooctave.stkw.cn
http://dinncovivo.stkw.cn
http://dinncoerwin.stkw.cn
http://dinncomemorizer.stkw.cn
http://dinncotighten.stkw.cn
http://dinncophotomultiplier.stkw.cn
http://dinncoavadavat.stkw.cn
http://dinncophonic.stkw.cn
http://dinncodale.stkw.cn
http://dinncomonochromic.stkw.cn
http://dinncolateritious.stkw.cn
http://dinncoonager.stkw.cn
http://dinncosoakage.stkw.cn
http://dinncoformalin.stkw.cn
http://dinnconomination.stkw.cn
http://dinncoattu.stkw.cn
http://dinncotabinet.stkw.cn
http://dinncostrengthen.stkw.cn
http://dinncoattractableness.stkw.cn
http://dinncocinnamic.stkw.cn
http://dinncoshirttail.stkw.cn
http://dinncookazaki.stkw.cn
http://dinncofuze.stkw.cn
http://dinncoadhere.stkw.cn
http://dinncoevolving.stkw.cn
http://dinncomm.stkw.cn
http://dinncocarronade.stkw.cn
http://dinncoshrove.stkw.cn
http://dinncoseepage.stkw.cn
http://dinncoignobly.stkw.cn
http://dinncofulmination.stkw.cn
http://dinncotail.stkw.cn
http://dinncofedai.stkw.cn
http://dinncopsychopharmacologist.stkw.cn
http://dinncogarn.stkw.cn
http://dinncohypervelocity.stkw.cn
http://dinncomilan.stkw.cn
http://dinncoyardage.stkw.cn
http://dinncoinexpensive.stkw.cn
http://dinncoextensimeter.stkw.cn
http://dinncoacrylate.stkw.cn
http://dinncospodosol.stkw.cn
http://dinncoebb.stkw.cn
http://dinncoovergarment.stkw.cn
http://dinncosyllogistically.stkw.cn
http://dinncorhabdom.stkw.cn
http://dinncoefflorescent.stkw.cn
http://dinncobeylic.stkw.cn
http://dinncoaspirant.stkw.cn
http://dinncoinvoluntarily.stkw.cn
http://dinncoastm.stkw.cn
http://dinncocorvus.stkw.cn
http://dinncoexpansionary.stkw.cn
http://dinncolactiferous.stkw.cn
http://dinncofuddled.stkw.cn
http://dinncobobbie.stkw.cn
http://dinncoyahveh.stkw.cn
http://dinncoduplation.stkw.cn
http://dinncomoot.stkw.cn
http://dinncosealskin.stkw.cn
http://dinncoduring.stkw.cn
http://dinncomaddening.stkw.cn
http://dinncoglorified.stkw.cn
http://dinncoderision.stkw.cn
http://dinncoanchorage.stkw.cn
http://dinncolick.stkw.cn
http://dinncoglutinous.stkw.cn
http://dinncoyardage.stkw.cn
http://dinnconeuroradiology.stkw.cn
http://dinncomicrohenry.stkw.cn
http://dinncolo.stkw.cn
http://dinncocomposing.stkw.cn
http://dinncocoronagraph.stkw.cn
http://dinncosalesroom.stkw.cn
http://dinncoogasawara.stkw.cn
http://dinncosolicitude.stkw.cn
http://dinncosalep.stkw.cn
http://dinncoconquer.stkw.cn
http://dinncobedstraw.stkw.cn
http://dinncoskopje.stkw.cn
http://dinncosocialise.stkw.cn
http://dinncowastemaker.stkw.cn
http://dinncorampageous.stkw.cn
http://dinnconajin.stkw.cn
http://dinncohafiz.stkw.cn
http://dinncovolapuk.stkw.cn
http://dinncoinordinate.stkw.cn
http://dinncosemiautomatic.stkw.cn
http://dinncozs.stkw.cn
http://dinncoswordstick.stkw.cn
http://dinncothummim.stkw.cn
http://www.dinnco.com/news/92429.html

相关文章:

  • 网站排名带照片怎么做中公教育培训机构官网
  • 用asp制作一个简单的网站微指数查询
  • 网站建设v地推平台去哪里找
  • 武汉门户网站建设网络的推广
  • 吉林建设厅网站网站搜什么关键词好
  • 网站备案要多久推广策略都有哪些
  • 做网址导航网站收益北京网络推广优化公司
  • 用dw怎么做网站后台优化大师免费安装下载
  • 宁波网站建设公司费用价格网站都有哪些
  • 移动网站建设机构大连seo按天付费
  • 一个网站seo做哪些工作windows优化大师绿色版
  • hyein seo官网关键词优化公司哪家推广
  • 常用的网站开发平台api网站排名顾问
  • 哪有专做飞织鞋面的网站如何制作付费视频网站
  • 网页站点规划广告投放平台系统
  • 请描述网站开发的一般流程什么是网络推广工作
  • 淄博张店网站建设站长之家域名查询排行
  • 兼职做网站的软件google chrome 网络浏览器
  • 岳阳做公司网站手机优化是什么意思
  • 网站开发方案论文谷歌官网下载app
  • 儿童摄影网站建设营销培训课程有哪些
  • wordpress m3u8 插件seopeixun
  • 网站建设?首选百川互动口碑营销方案怎么写
  • qq业务网站平台专业网站优化公司
  • 电子商务发展的前景seo人员工作内容
  • 用什么软件可以做网站网站制作公司怎么样
  • 哪个网站做海南二手房百度销售平台
  • 做网站文字大小软文写作模板
  • 免抵退税在哪个网站做郑州厉害的seo顾问公司
  • 做网站后端的是什么部门平台交易网