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

网站如何做ins链接分享网站网上预定功能怎么做

网站如何做ins链接分享,网站网上预定功能怎么做,网站系统里不能打印,江西网站建设价位命令模式#xff08;Command Pattern#xff09;是用来实现在一个请求 - 响应模型松耦合。在命令模式中#xff0c;请求被发送给调用者和调用它传递给被封装的命令对象。 Command对象将请求传递到接收器的适当的方法来执行特定操作。客户端程序创建接收器对象#xff0c;然… 命令模式Command Pattern是用来实现在一个请求 - 响应模型松耦合。在命令模式中请求被发送给调用者和调用它传递给被封装的命令对象。 Command对象将请求传递到接收器的适当的方法来执行特定操作。客户端程序创建接收器对象然后将其连接到命令。然后它会创建调用对象和附加命令对象执行的操作。现在当客户端程序执行的操作它是基于命令和接收对象的处理。 我们将着眼于真实的生活场景我们可以实现Command模式。比方说我们希望提供一个文件系统工具与具体操作文件的打开写入和关闭文件功能它应该支持多种操作系统如Windows和Unix。 为了实现我们的文件系统工具首先我们需要创建一个接收器类实现以上所有的工作。由于我们在Java依据接口设计我们可以有FileSystemReceiver接口和它的实现类实现不同的操作系统如WindowsUNIX的Solaris等 FileSystemReceiver.java package com.journaldev.design.command;public interface FileSystemReceiver {void openFile();void writeFile();void closeFile(); } FileSystemReceiver接口定义了实现类实现规则方法为了简单我只创建了windowslinux两个接收器。 UnixFileSystemReceiver.java package com.journaldev.design.command;public class UnixFileSystemReceiver implements FileSystemReceiver {Overridepublic void openFile() {System.out.println(Opening file in unix OS);}Overridepublic void writeFile() {System.out.println(Writing file in unix OS);}Overridepublic void closeFile() {System.out.println(Closing file in unix OS);}} WindowsFileSystemReceiver.java package com.journaldev.design.command;public class WindowsFileSystemReceiver implements FileSystemReceiver {Overridepublic void openFile() {System.out.println(Opening file in Windows OS);}Overridepublic void writeFile() {System.out.println(Writing file in Windows OS);}Overridepublic void closeFile() {System.out.println(Closing file in Windows OS);}} conmand接口设计与实现 我们可以使用接口或抽象类实现具体实现取决于你的需求这里我仍使用接口实现 package com.journaldev.design.command;public interface Command {void execute(); }现在我们需要创建实现所有不同类型的action由接收器进行的因为我们有三个acton我们将创建三个命令实现每个命令执行将请求转发到接收器的适当的方法。 OpenFileCommand.java package com.journaldev.design.command;public class OpenFileCommand implements Command {private FileSystemReceiver fileSystem;public OpenFileCommand(FileSystemReceiver fs){this.fileSystemfs;}Overridepublic void execute() {//open command is forwarding request to openFile methodthis.fileSystem.openFile();}} CloseFileCommand.java package com.journaldev.design.command;public class CloseFileCommand implements Command {private FileSystemReceiver fileSystem;public CloseFileCommand(FileSystemReceiver fs){this.fileSystemfs;}Overridepublic void execute() {this.fileSystem.closeFile();}} WriteFileCommand.java package com.journaldev.design.command;public class WriteFileCommand implements Command {private FileSystemReceiver fileSystem;public WriteFileCommand(FileSystemReceiver fs){this.fileSystemfs;}Overridepublic void execute() {this.fileSystem.writeFile();}} 现在接收器与Conmand实现已完成下面实现调用类。 调用是封装的命令和请求传递给命令对象来处理它一个简单的类。 FileInvoker.java package com.journaldev.design.command;public class FileInvoker {public Command command;public FileInvoker(Command c){this.commandc;}public void execute(){this.command.execute();} } FileSystemReceiverUtil.java package com.journaldev.design.command;public class FileSystemReceiverUtil {public static FileSystemReceiver getUnderlyingFileSystem(){String osName System.getProperty(os.name);System.out.println(Underlying OS is:osName);if(osName.contains(Windows)){return new WindowsFileSystemReceiver();}else{return new UnixFileSystemReceiver();}}} 下面创建客户端类使用我们的文件系统Util FileSystemClient.java package com.journaldev.design.command;public class FileSystemClient {public static void main(String[] args) {//Creating the receiver objectFileSystemReceiver fs FileSystemReceiverUtil.getUnderlyingFileSystem();//creating command and associating with receiverOpenFileCommand openFileCommand new OpenFileCommand(fs);//Creating invoker and associating with CommandFileInvoker file new FileInvoker(openFileCommand);//perform action on invoker objectfile.execute();WriteFileCommand writeFileCommand new WriteFileCommand(fs);file new FileInvoker(writeFileCommand);file.execute();CloseFileCommand closeFileCommand new CloseFileCommand(fs);file new FileInvoker(closeFileCommand);file.execute();}} 程序输出 Underlying OS is:Mac OS X Opening file in unix OS Writing file in unix OS Closing file in unix OS 类结构视图 要点总结 命令是这种模式它定义了规则执行核心。 接收机的实现是由分开的命令执行。 命令实现类选择的方法来调用接收对象每个方法的接收器会有一个命令执行。它的工作原理是接收器和行动方法之间的桥梁。 调用类从客户端获取请求将命令对象转发。 客户端负责实例化相应的命令并接收执行然后将它们联系到一起。 客户端还负责调用实例化对象并与之关联的命令对象并执行该操作方法。 Command模式很容易扩展的我们可以在接收器中添加新的操作方法并创建新的命令的实现在不改变客户端代码。 command模式的缺点是代码量是巨大的因为这么多的关联和混乱有大量的动作和方法。 转载于:https://www.cnblogs.com/happyxiaoyu02/p/6818938.html
http://www.zqtcl.cn/news/334516/

相关文章:

  • 张家界做网站洛阳网站建设哪家专业
  • 快餐网站模板电子版邀请函制作软件免费
  • 有什么做视频的素材网站网站名称注册保护
  • 北京 顺义 网站制作h5网站网站建设
  • 网站在百度上搜不到了wordpress导航菜单加图片
  • wordpress网站访问慢网站建设35类
  • 绍兴做网站价格字体
  • asp.net网站开发实训可以不花钱做网站吗
  • 北京网站的制作设计服务器和电脑主机的区别
  • 北京网站建设的服务公司凡科网站 怎么开支付
  • 包头公司做网站知名做网站费用
  • 安徽网站建设服务平台重庆网站建公司大全
  • 有什么网站可以做中间人的相城区建设局网站
  • 房屋装修在线设计网站百度联盟广告怎么屏蔽
  • 网站,商城,app+建设域名网址注册
  • 肥西做网站设计网页页面
  • 怎样做百度推广网站iis服务器的默认网站
  • 东莞建设工程交易中心门户网站湖南设计网站机构
  • 做网站在网站建设客户
  • 河北建设厅安监站官方网站一个新手怎么做电商
  • 做结婚请柬网站有那些做网店哪个网站好
  • 做网站尽在美橙互联欧美简约风格网站设计
  • idea建设完整的网站微官网下载
  • 阿城区建设小学网站上海建设行政主管部门政务网站
  • 西丽网站建设网站怎样做才能有点击率
  • 网站建设图片大小建设部网站1667号公告
  • 做wps的网站赚钱网站建设中网站图片如何修改
  • 公司招商型网站建设怎么自己做网站挣钱
  • 红酒手机网站建设中视频自媒体注册
  • 免费网站2022年能用的网址青阳网站建设