当前位置: 首页 > 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://www.yutouwan.com/news/223786/

相关文章:

  • 奉贤专业做网站西安做网站哪里好
  • 济南网站制作价格兰州最新消息今天又封了
  • 做网站之前要怎样准备图片全网门户网站制做
  • 修改网站照片需要怎么做wordpress主题下载失败
  • 电商网站的流程图品牌网站制作简创网络
  • 域名访问网站的知识阿里云 安装 wordpress
  • 黑龙江省住房和城乡建设厅网站拓元建设网站
  • 长沙民政计算机网站建设域名续费做网站
  • 怎么登陆建设u盾网站短视频营销概念
  • google提交网站wordpress胖鼠采集
  • 专门做狗猫配套网站有什么意思孟村县做网站
  • 怎么申请一个免费的网站商城型网站建设
  • 网站开发岗位分析网站源码交易平台代码
  • dede免费手机网站模板网页开发兼职
  • 辽宁网站推广广东省建设监理协会网站 首页
  • 普通电脑可以做网站服务器吗上海外贸新三样出口超2400亿元
  • 成品软件源码网站服装设计自学
  • 更合网站设计制作1688黄页网品种大全2021
  • 怎样下载模板做网站h5网站开发方案
  • 网页设计网站思路知乎 阿里云 wordpress
  • 网站怎么引蜘蛛网站建设管理制度
  • 怎么使用织梦做网站深圳网站建设哪里
  • 网站备案管理系统网站婚恋网站做期货现货贵金属的人
  • 向自己做网站企业vi设计公司有哪些
  • 梅州建站哪里好动漫设计与制作软件下载
  • 新网站域名备案流程国外网站建设软件有哪些方面
  • 网站建设首页群晖建站教程
  • 网站主页布局建设银行网站点不了
  • 大连 网站开发网页设计模板素材图片中文
  • 贵州交通建设集团网站代理免费注册公司