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

建设银行网站怎样查询贷款信息吗网站源码模块

建设银行网站怎样查询贷款信息吗,网站源码模块,找合作项目的平台,客户求购平台文章目录 举例说明优点缺点完整代码 With the Command Pattern, we can decouple objects that execute a certain task from the object that calls the method. 使用命令模式#xff0c;我们可以将执行特定任务的对象与调用该方法的对象解耦。 怎么理解 执行特定任务的对… 文章目录 举例说明优点缺点完整代码 With the Command Pattern, we can decouple objects that execute a certain task from the object that calls the method. 使用命令模式我们可以将执行特定任务的对象与调用该方法的对象解耦。 怎么理解 执行特定任务的对象 与 调用该方法的对象解耦 使用命令模式我们可以将执行特定任务的对象与调用该方法执行特定任务的对象解耦。也即将执行与调用解耦。 举例说明 Let’s say we have an online food delivery platform. Users can place, track, and cancel orders. 假设我们有一个在线外卖平台。用户可以下订单、跟踪和取消订单。 class OrderManager() {constructor() {this.orders []}placeOrder(order, id) {this.orders.push(id)return You have successfully ordered ${order} (${id});}trackOrder(id) {return Your order ${id} will arrive in 20 minutes.}cancelOrder(id) {this.orders this.orders.filter(order order.id ! id)return You have canceled your order ${id}} } On the OrderManager class, we have access to the placeOrder, trackOrder and cancelOrder methods. It would be totally valid JavaScript to just use these methods directly! 在OrderManager类中可以访问placeOrder、trackOrder和cancelOrder方法。直接使用这些方法将是完全有效的JavaScript ! const manager new OrderManager();manager.placeOrder(Pad Thai, 1234); manager.trackOrder(1234); manager.cancelOrder(1234); However, there are downsides to invoking the methods directly on the manager instance. It could happen that we decide to rename certain methods later on, or the functionality of the methods change. 直接通过manager实例调用这些方法也有潜在的问题。以后可能决定重命名某些方法或者这些方法的功能发生了变化。 Say that instead of calling it placeOrder, we now rename it to addOrder! This would mean that we would have to make sure that we don’t call the placeOrder method anywhere in our codebase, which could be very tricky in larger applications. Instead, we want to decouple the methods from the manager object, and create separate command functions for each command! 现在我们将placeOrder重命名为addOrder。这意味着我们必须确保不在代码库的任何地方调用placeOrder方法这在大型应用程序中可能非常棘手。相反我们希望将方法与manager对象解耦并为每个命令创建单独的命令函数! Let’s refactor the OrderManager class: instead of having the placeOrder, cancelOrder and trackOrder methods, it will have one single method: execute. This method will execute any command it’s given. 让我们重构OrderManager类:代替placeOrder、cancelOrder和trackOrder方法它将只有一个方法:execute。这个方法将执行给定的任何命令。 Each command should have access to the orders of the manager, which we’ll pass as its first argument. 每个命令都应该能够访问管理器的订单我们将把它作为第一个参数传递给execute。 class OrderManager {constructor() {this.orders [];}execute(command, ...args) {return command.execute(this.orders, ...args);} } We need to create three **Command**s for the order manager: PlaceOrderCommandCancelOrderCommandTrackOrderCommand class Command {constructor(execute) {this.execute execute;} }function PlaceOrderCommand(order, id) {return new Command((orders) {orders.push(id);return You have successfully ordered ${order} (${id});}); }function CancelOrderCommand(id) {return new Command((orders) {orders orders.filter((order) order.id ! id);return You have canceled your order ${id};}); }function TrackOrderCommand(id) {return new Command(() Your order ${id} will arrive in 20 minutes.); } Perfect! Instead of having the methods directly coupled to the OrderManager instance, they’re now separate, decoupled functions that we can invoke through the execute method that’s available on the OrderManager. 完美!不是将方法直接耦合到OrderManager实例它们现在是分离的、解耦的函数我们可以通过OrderManager上可用的execute方法调用它们。 优点 The command pattern allows us to decouple methods from the object that executes the operation. It gives you more control if you’re dealing with commands that have a certain lifespan, or commands that should be queued and executed at specific times. 命令模式允许我们将方法与执行该方法的对象解耦。如果您正在处理具有特定生命周期的命令或者应该在特定时间排队并执行的命令那么它可以为您提供更多的控制。 缺点 The use cases for the command pattern are quite limited, and often adds unnecessary boilerplate to an application. 命令模式的使用场景非常有限并且经常向应用程序添加不必要的样板代码。 完整代码 class OrderManager {constructor() {this.orders [];}execute(command, ...args) {return command.execute(this.orders, ...args);} }class Command {constructor(execute) {this.execute execute;} }function PlaceOrderCommand(order, id) {return new Command(orders {orders.push(id);console.log(You have successfully ordered ${order} (${id}));}); }function CancelOrderCommand(id) {return new Command(orders {orders orders.filter(order order.id ! id);console.log(You have canceled your order ${id});}); }function TrackOrderCommand(id) {return new Command(() console.log(Your order ${id} will arrive in 20 minutes.)); }const manager new OrderManager();manager.execute(new PlaceOrderCommand(Pad Thai, 1234)); manager.execute(new TrackOrderCommand(1234)); manager.execute(new CancelOrderCommand(1234));
http://www.sadfv.cn/news/86180/

相关文章:

  • 注册网站流程及资料网页设计费用明细
  • 做淘客需要网站南京哪家网站建设比较好
  • 广州专业网站建设企业无代码网站开发
  • 网站建设比较好的机械制造设备类企业网站织梦模板
  • phpmysql网站开发案例网站后台账户如何做会计分录
  • 网页制作网站创建南昌专业网站建设公司
  • 做代加工的网站发布住建部证书查询大厅
  • 品牌网站建设工作室张家口外贸网站建设
  • 私人网站服务器免费企业网站怎么做省钱
  • 免费网站在线观看常用的编辑html的软件
  • 做网站PV网站负责人备案采集照具体要求
  • 如何添加网站代码江门外贸网站建设
  • 企业做网站的痛点有哪些深圳营销型网站定制
  • 手车做网课网站wordpress样式表
  • 官方微网站构站网
  • 寄生虫网站怎么做中国建设银行深圳分行网站
  • 机关建设网站i57500网站开发
  • 重庆设计网站wordpress 文档阅读器
  • 设计很好看的网站中国制造网外贸
  • 郑州建网站十大合肥高端网站建设设计公司
  • 网站建设i外部调用wordpress站点文章
  • php做网站需要html做网站需要做哪些东西
  • 免费网站服务器租用工程建设标准化是正规期刊吗
  • 网站制作公司排名前十郑州网站的优化
  • 网站没有做的关键词有排名icp备案查询官方网站
  • 青岛网站建设哪家更好做网站备完备案需要干什么
  • 如何做自己的网站wordpress 获取导航
  • 宁夏网站建设优化做外贸在什么网站最好
  • 一个帮你赚钱的网站是谁做的广告建筑模板多少钱一平方
  • 个人网站设计介绍文字推广员是做什么的