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

网站制作网站建站电商小程序需要什么资质

网站制作网站建站,电商小程序需要什么资质,怎样做优惠券网站,58同城网站建设问题中介者模式是一种行为设计模式#xff0c;可以减少对象之间混乱无序的依赖关系。该模式会限制对象之间的直接交互#xff0c;迫使它们通过一个封装了对象间交互行为的中介者对象来进行合作#xff0c;从而使对象间耦合松散#xff0c;并可独立地改变它们之间的交互。中介者…中介者模式是一种行为设计模式可以减少对象之间混乱无序的依赖关系。该模式会限制对象之间的直接交互迫使它们通过一个封装了对象间交互行为的中介者对象来进行合作从而使对象间耦合松散并可独立地改变它们之间的交互。中介者模式又称为调停者模式。 Mediator is a behavior design pattern. It can reduce the disordered dependencies between objects. This pattern restricts direct interaction between objects, forcing them to collaborate through a mediator object that encapsulates the interaction behavior between objects, resulting in loose coupling between objects and the ability to independently change their interactions. 结构设计 中介者模式包含如下角色 Component组件基类声明组件的基本功能有一个指向中介者的引用该引用被声明为中介者接口类型。组件不知道中介者实际所属的类因此可通过将其连接到不同的中介者以使其能在其他程序中复用。 Mediator中介者接口声明了与组件交流的方法但通常仅包括一个通知方法。组件可将任意上下文作为该方法的参数只有这样接收组件和发送者类之间才不会耦合。 ConcreteComponent具体组件实现组件声明的方法并自定义业务逻辑接口。 ConcreteMediator具体中介者实现中介者接口声明的方法。 中介者模式类图表示如下 伪代码实现 接下来将使用代码介绍下中介者模式的实现。 // 1、中介者接口声明了与组件交流的方法 public interface IMediator {void notify(Sender sender); }//2、具体中介者实现中介者接口声明的方法 public class ConcreteMediator implements IMediator {Overridepublic void notify(Sender sender) {String message sender.getMessage();Component target sender.getTarget();target.operation(message);} }// 3、组件基类声明组件的基本功能有一个指向中介者的引用该引用被声明为中介者接口类型 public abstract class Component {protected IMediator mediator;public Component(IMediator mediator) {this.mediator mediator;}public void operation(String message) {System.out.println(message is message);}public void send(String message, Component target) {Sender sender new Sender(message, this, target);mediator.notify(sender);} }// 4、具体组件实现组件声明的方法并自定义业务逻辑接口 public class ConcreteComponentA extends Component {public ConcreteComponentA(IMediator mediator) {super(mediator);}Overridepublic void operation(String message) {super.operation(message);operationA();}public void operationA() {System.out.println(operationA in a Concrete ComponentA instance);} } public class ConcreteComponentB extends Component {public ConcreteComponentB(IMediator mediator) {super(mediator);}Overridepublic void operation(String message) {super.operation(message);operationB();}public void operationB() {System.out.println(operationB in a Concrete ComponentB instance);} } public class ConcreteComponentC extends Component {public ConcreteComponentC(IMediator mediator) {super(mediator);}Overridepublic void operation(String message) {super.operation(message);operationC();}public void operationC() {System.out.println(operationC in a Concrete ComponentC instance);} } public class ConcreteComponentD extends Component {public ConcreteComponentD(IMediator mediator) {super(mediator);}Overridepublic void operation(String message) {super.operation(message);operationD();}public void operationD() {System.out.println(operationD in a Concrete ComponentD instance);} }// 5、客户端 public class MediatorClient {public void test() {IMediator mediator new ConcreteMediator();Component componentA new ConcreteComponentA(mediator);Component componentB new ConcreteComponentB(mediator);Component componentC new ConcreteComponentC(mediator);Component componentD new ConcreteComponentD(mediator);componentA.send(i am a, componentB);componentB.send(i am b, componentC);componentC.send(i am c, componentD);componentD.send(i am d, componentA);} }public class Sender {private String message;private Component source;private Component target;public Sender(String message, Component source, Component target) {this.message message;this.source source;this.target target;}public String getMessage() {return this.message;}public Component getSource() {return this.source;}public Component getTarget() {return this.target;} }适用场景 在以下情况下可以考虑使用中介者模式 (1) 当一些对象和其他对象紧密耦合产生的相互依赖关系结构混乱且难以理解从而导致难以对其进行修改时可考虑使用中介者模式。中介者模式可将对象间的所有关系抽取成为一个单独的类 以使对于特定组件的修改工作独立于其他组件。 (2) 当组件因过于依赖其他组件而无法在不同应用中复用时可考虑使用中介者模式。应用中介者模式后 每个组件不再知晓其他组件的情况。尽管这些组件无法直接交流但它们仍可通过中介者对象进行间接交流。 如果希望在不同应用中复用一个组件则需要为其提供一个新的中介者类。 (3) 如果为了能在不同情景下复用一些基本行为导致需要被迫创建大量组件子类时可考虑使用中介者模式。由于所有组件间关系都被包含在中介者中 因此无需修改组件就能方便地新建中介者类以定义新的组件合作方式。 优缺点 中介者模式有以下优点 (1) 符合单一职责原则。可以将多个组件间的交流抽取到同一位置使其更易于理解和维护。 (2) 符合开闭原则。无需修改实际组件就能增加新的中介者。 (3) 可以减轻应用中多个组件间的耦合情况。 但是该模式也存在以下缺点 (1) 在具体中介者类中包含了组件之间的交互细节可能会导致具体中介者类非常复杂使得系统难以维护。一段时间后中介者可能会演化成为上帝对象。 参考 《设计模式 可复用面向对象软件的基础》 Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides 著, 李英军, 马晓星等译 https://design-patterns.readthedocs.io/zh_CN/latest/behavioral_patterns/mediator.html 中介者模式 https://refactoringguru.cn/design-patterns/mediator 中介者模式 https://www.runoob.com/design-pattern/mediator-pattern.html 中介者模式 https://www.cnblogs.com/adamjwh/p/10959987.html 简说设计模式——中介者模式
http://wiki.neutronadmin.com/news/223786/

相关文章:

  • 门户网站建设和检务公开整改外贸公司怎么找客户
  • 为网站设计手机版自己建的网站地址
  • 企业网站建设用标语网站如何在国外推广
  • 如何架设网站服务器邯郸市住房公积金管理中心
  • 网站已备案添加新域名电商平台网站有哪些
  • 广西网站建设教程wordpress 图片管理插件
  • 佛山网站推广市场设计建网站
  • 济南建设网站公司哪个好苏州企业网站设计方案
  • 房地产网站制作教程多少钱翻译
  • 怎么做网站竞价推广可以进网站的软件
  • 东南亚购物网站排名京东联盟 wordpress
  • 网站排名软件推荐wordpress 证书风险
  • 老域名做网站阿里巴巴网站建设的目的
  • 关于春节的网站设计html世界互联网峰会2022
  • 资兴市建设局网站阿里巴巴国际站下载电脑版
  • 电脑报网站建设成品网站货源
  • 免费的关键词优化工具广东搜索引擎优化
  • 网站建设套餐电话wordpress query_post showpost参数
  • 北京 网站设计招聘信息上海网站建设乐云seo
  • 花市小说网站那里进邢台信息港最新二手房出售信息
  • 网站怎么做定位功能交通局网站模板
  • 两性做受技巧视频网站网站备案需要审核多久
  • 合肥论坛网站制作移动网站开发服务器
  • 手机做的兼职网站wordpress如何开启邀请码注册
  • 前端开发培训机构哪家好长沙网站seo服务
  • 做网站要知道哪些代码添加了字体为什么wordpress
  • 邯郸医疗网站建设新网站建设验收
  • 成都网站建设联系电话photoshop破解版下载免费中文版
  • 网站建设优化的技巧如何做网络营销推广掷25金手指效率高
  • 美妆网站制作教程营销型网站开发方案