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

网站源代码下载工具电脑培训机构

网站源代码下载工具,电脑培训机构,西安网站开发公司排名,如何给自己的网站做优化目录 定义结构适用场景使用示例 定义 外观模式(Facade Pattern)‌ 是一种结构型设计模式,它提供了一个统一的接口,用来访问子系统中的一组接口。外观模式定义了一个高层接口,这个接口使得子系统更容易使用。 结构 适用…

目录

  • 定义
  • 结构
  • 适用场景
  • 使用示例

定义

       外观模式(Facade Pattern)‌ 是一种结构型设计模式,它提供了一个统一的接口,用来访问子系统中的一组接口。外观模式定义了一个高层接口,这个接口使得子系统更容易使用。

结构

在这里插入图片描述

适用场景

       1)为复杂的子系统提供简单入口
       2)统一管理系统中存在的多个复杂的子系统
       3)解耦客户端与多个子系统之间的依赖关系
       4)分层系统中,作为层与层之间的通信接口
       5)为遗留系统提供新的简化接口

使用示例

      简单的电商订单示例
      定义各个模拟子系统

/*** 库存子系统*/
public class InventoryService {public boolean checkStock(String productId, int quantity) {System.out.println("检查库存: 产品" + productId + " 数量" + quantity);return true;}public void lockStock(String productId, int quantity) {System.out.println("锁定库存: 产品" + productId + " 数量" + quantity);}}
/*** 通知子系统*/
public class NotificationService {public void sendConfirmation(String userId, String orderId) {System.out.println("发送确认通知: 用户" + userId + " 订单" + orderId);}}
/*** 支付子系统*/
public class PaymentService {public boolean processPayment(String userId, double amount) {System.out.println("处理支付: 用户" + userId + " 金额" + amount);return true;}}
/*** 物流子系统*/
public class ShippingService {public String scheduleDelivery(String orderId) {String trackingNo = "TRK" + System.currentTimeMillis();System.out.println("安排配送: 订单" + orderId + " 物流单号" + trackingNo);return trackingNo;}}

      定义外观门面

/*** 外观:订单处理门面*/
public class OrderProcessFacade {private InventoryService inventory;private PaymentService payment;private ShippingService shipping;private NotificationService notification;public OrderProcessFacade() {this.inventory = new InventoryService();this.payment = new PaymentService();this.shipping = new ShippingService();this.notification = new NotificationService();}// 统一订单处理接口public String placeOrder(String userId, String productId, int quantity, double amount) {System.out.println("\n开始处理订单...");if (!inventory.checkStock(productId, quantity)) {throw new RuntimeException("库存不足");}inventory.lockStock(productId, quantity);if (!payment.processPayment(userId, amount)) {throw new RuntimeException("支付失败");}String orderId = "ORD" + System.currentTimeMillis();String trackingNo = shipping.scheduleDelivery(orderId);notification.sendConfirmation(userId, orderId);System.out.println("订单处理完成: " + orderId);return orderId;}}

      测试

public class OrderController {public static void main(String[] args) {OrderProcessFacade orderFacade = new OrderProcessFacade();String orderId = orderFacade.placeOrder("user123", "prod1001", 2, 299.99);System.out.println("生成的订单号: " + orderId);}}
http://www.dtcms.com/wzjs/178254.html

相关文章:

  • 那些网站招聘在家里做的客服做一个网站要花多少钱
  • 无锡网站建设开发站长网站查询工具
  • 做宠物商品的网站南宁百度推广seo
  • wordpress英文仿站教程关键字c语言
  • 怎么做英文的网站seo手机关键词网址
  • 超酷网站模板seo面试常见问题及答案
  • php做的网站好不好2022年最火的新闻摘抄
  • 网站设计建设公司教程以下属于网站seo的内容是
  • 无极app定制开发公司网站模板关键词优化排名公司
  • 风铃做的网站能否推广列举五种网络营销模式
  • .net简单网站开发视频教程网站排名top排行榜
  • 织梦做不了视频网站seo描述是什么意思
  • html代码表示什么搜索引擎优化实训报告
  • 上海做高端网站建设怎么做表格
  • 株洲建设网站公司互动营销策略
  • 优化网站排名公司百度答主招募入口官网
  • 网站页面设计效果图东莞市网络营销公司
  • 舞蹈网页设计素材南宁关键词优化软件
  • 阿里云网站备案资料企业官网seo
  • 专业的团队网站建设推广的方式有哪些
  • 小程序搭建赚钱是真的吗福州百度seo排名软件
  • 深圳做网站j华信科广东网站营销seo方案
  • 去哪里做网站网站seo策划方案案例分析
  • 鄂州市政府官网百度seo多久能优化关键词
  • 北京安慧桥网站建设2023年火爆的新闻
  • 公司注册代办上海石家庄seo
  • 商丘网站建设费用长沙seo优化报价
  • 龙岩装修公司seo关键词的优化技巧
  • 北京上地网站建设关键词录入榜
  • 网站建设b2b2c百度推广代理商与总公司的区别