流量网站制作,前端网页,做模型找三视图那些网站,四川建设人才网官网登录引言 
中介者模式#xff08;Mediator Pattern#xff09;是一种行为设计模式#xff0c;它通过引入一个中介对象来封装对象之间的交互#xff0c;从而使对象不需要显式地相互引用#xff0c;从而降低了对象之间的耦合性。在金融业务中#xff0c;中介者模式常用于实现复…引言 
中介者模式Mediator Pattern是一种行为设计模式它通过引入一个中介对象来封装对象之间的交互从而使对象不需要显式地相互引用从而降低了对象之间的耦合性。在金融业务中中介者模式常用于实现复杂的交易系统、消息传递系统等。本文将介绍中介者模式在金融业务中的使用并探讨其在Spring框架中的实现方式。 
设计原理 
中介者模式主要涉及以下几个角色 
中介者Mediator定义一个接口用于与各同事对象通信。具体中介者Concrete Mediator实现中介者接口协调各同事对象之间的交互。同事类Colleague各同事类只知道中介者而不知道其他同事类从而通过中介者进行通信。 
类图 
下图展示了中介者模式的类图 #mermaid-svg-uoS6LsX8meHzQ3mf {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-uoS6LsX8meHzQ3mf .error-icon{fill:#552222;}#mermaid-svg-uoS6LsX8meHzQ3mf .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-uoS6LsX8meHzQ3mf .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-uoS6LsX8meHzQ3mf .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-uoS6LsX8meHzQ3mf .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-uoS6LsX8meHzQ3mf .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-uoS6LsX8meHzQ3mf .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-uoS6LsX8meHzQ3mf .marker{fill:#333333;stroke:#333333;}#mermaid-svg-uoS6LsX8meHzQ3mf .marker.cross{stroke:#333333;}#mermaid-svg-uoS6LsX8meHzQ3mf svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-uoS6LsX8meHzQ3mf g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-uoS6LsX8meHzQ3mf g.classGroup text .title{font-weight:bolder;}#mermaid-svg-uoS6LsX8meHzQ3mf .nodeLabel,#mermaid-svg-uoS6LsX8meHzQ3mf .edgeLabel{color:#131300;}#mermaid-svg-uoS6LsX8meHzQ3mf .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-uoS6LsX8meHzQ3mf .label text{fill:#131300;}#mermaid-svg-uoS6LsX8meHzQ3mf .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-uoS6LsX8meHzQ3mf .classTitle{font-weight:bolder;}#mermaid-svg-uoS6LsX8meHzQ3mf .node rect,#mermaid-svg-uoS6LsX8meHzQ3mf .node circle,#mermaid-svg-uoS6LsX8meHzQ3mf .node ellipse,#mermaid-svg-uoS6LsX8meHzQ3mf .node polygon,#mermaid-svg-uoS6LsX8meHzQ3mf .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-uoS6LsX8meHzQ3mf .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-uoS6LsX8meHzQ3mf g.clickable{cursor:pointer;}#mermaid-svg-uoS6LsX8meHzQ3mf g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-uoS6LsX8meHzQ3mf g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-uoS6LsX8meHzQ3mf .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-uoS6LsX8meHzQ3mf .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-uoS6LsX8meHzQ3mf .dashed-line{stroke-dasharray:3;}#mermaid-svg-uoS6LsX8meHzQ3mf #compositionStart,#mermaid-svg-uoS6LsX8meHzQ3mf .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf #compositionEnd,#mermaid-svg-uoS6LsX8meHzQ3mf .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf #dependencyStart,#mermaid-svg-uoS6LsX8meHzQ3mf .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf #dependencyStart,#mermaid-svg-uoS6LsX8meHzQ3mf .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf #extensionStart,#mermaid-svg-uoS6LsX8meHzQ3mf .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf #extensionEnd,#mermaid-svg-uoS6LsX8meHzQ3mf .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf #aggregationStart,#mermaid-svg-uoS6LsX8meHzQ3mf .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf #aggregationEnd,#mermaid-svg-uoS6LsX8meHzQ3mf .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-uoS6LsX8meHzQ3mf .edgeTerminals{font-size:11px;}#mermaid-svg-uoS6LsX8meHzQ3mf :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}                                                                                                                                   Mediator     send(message: String, colleague: Colleague)                 ConcreteMediator     - colleague1: Colleague1     - colleague2: Colleague2     send(message: String, colleague: Colleague)                 Colleague     send(message: String)     receive(message: String)                 Colleague1     send(message: String)     receive(message: String)                 Colleague2     send(message: String)     receive(message: String)         中介者模式在金融业务中的应用 
1. 交易系统 
在金融交易系统中多个模块需要相互通信和协调例如订单管理、风控管理等。中介者模式可以用于实现这种模块间的解耦和协调。 
// 中介者接口
public interface Mediator {void send(String message, Colleague colleague);
}// 具体中介者类
public class ConcreteMediator implements Mediator {private Colleague1 colleague1;private Colleague2 colleague2;public void setColleague1(Colleague1 colleague1) {this.colleague1  colleague1;}public void setColleague2(Colleague2 colleague2) {this.colleague2  colleague2;}Overridepublic void send(String message, Colleague colleague) {if (colleague  colleague1) {colleague2.receive(message);} else {colleague1.receive(message);}}
}// 同事类
public abstract class Colleague {protected Mediator mediator;public Colleague(Mediator mediator) {this.mediator  mediator;}public abstract void send(String message);public abstract void receive(String message);
}// 具体同事类1
public class Colleague1 extends Colleague {public Colleague1(Mediator mediator) {super(mediator);}Overridepublic void send(String message) {System.out.println(Colleague1 sends message:   message);mediator.send(message, this);}Overridepublic void receive(String message) {System.out.println(Colleague1 receives message:   message);}
}// 具体同事类2
public class Colleague2 extends Colleague {public Colleague2(Mediator mediator) {super(mediator);}Overridepublic void send(String message) {System.out.println(Colleague2 sends message:   message);mediator.send(message, this);}Overridepublic void receive(String message) {System.out.println(Colleague2 receives message:   message);}
}// 客户端代码
public class MediatorPatternDemo {public static void main(String[] args) {ConcreteMediator mediator  new ConcreteMediator();Colleague1 colleague1  new Colleague1(mediator);Colleague2 colleague2  new Colleague2(mediator);mediator.setColleague1(colleague1);mediator.setColleague2(colleague2);colleague1.send(Hi there!);colleague2.send(Hello!);}
}中介者模式在Spring框架中的应用 
Spring Integration 
Spring Integration是Spring框架的一个模块旨在简化系统集成通过消息传递实现模块间的松耦合。它利用中介者模式通过引入消息通道和消息网关来实现组件之间的通信。 
1. Spring Integration 配置示例 
!-- 定义消息通道 --
int:channel idinputChannel/
int:channel idoutputChannel/!-- 定义服务激活器 --
int:service-activator input-channelinputChannel output-channeloutputChannel refmyService methodprocess/!-- 定义消息处理器 --
bean idmyService classcom.example.MyService/!-- 定义消息网关 --
int:gateway idmyGateway service-interfacecom.example.MyGateway default-request-channelinputChannel/2. Spring Integration 服务示例 
public interface MyGateway {String sendMessage(String message);
}public class MyService {public String process(String message) {System.out.println(Processing message:   message);return Processed:   message;}
}// 客户端代码
public class SpringIntegrationDemo {public static void main(String[] args) {ApplicationContext context  new ClassPathXmlApplicationContext(spring-integration-config.xml);MyGateway gateway  context.getBean(MyGateway.class);String response  gateway.sendMessage(Hello Spring Integration!);System.out.println(response);}
}总结 
中介者模式在金融业务中具有广泛的应用可以灵活地实现模块间的解耦和协调。在Spring框架中中介者模式通过Spring Integration得到了广泛应用使得系统更具灵活性和可扩展性。 
参考文献 
Refactoring Guru - Mediator PatternSpring Integration Documentation 
互动与反馈 
如果你觉得这篇文章对你有帮助请点赞、收藏并关注我以便获得更多优质内容如有疑问或建议欢迎在评论区留言我会及时回复。感谢阅读 文章转载自: http://www.morning.kyctc.cn.gov.cn.kyctc.cn http://www.morning.ljbpk.cn.gov.cn.ljbpk.cn http://www.morning.gypcr.cn.gov.cn.gypcr.cn http://www.morning.pnmnl.cn.gov.cn.pnmnl.cn http://www.morning.qfzjn.cn.gov.cn.qfzjn.cn http://www.morning.bydpr.cn.gov.cn.bydpr.cn http://www.morning.gqjzp.cn.gov.cn.gqjzp.cn http://www.morning.fewhope.com.gov.cn.fewhope.com http://www.morning.hlkxb.cn.gov.cn.hlkxb.cn http://www.morning.rrwft.cn.gov.cn.rrwft.cn http://www.morning.ykrck.cn.gov.cn.ykrck.cn http://www.morning.psdsk.cn.gov.cn.psdsk.cn http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn http://www.morning.kdbbm.cn.gov.cn.kdbbm.cn http://www.morning.ttxnj.cn.gov.cn.ttxnj.cn http://www.morning.jbblf.cn.gov.cn.jbblf.cn http://www.morning.pcngq.cn.gov.cn.pcngq.cn http://www.morning.ppzgr.cn.gov.cn.ppzgr.cn http://www.morning.gglhj.cn.gov.cn.gglhj.cn http://www.morning.lkhfm.cn.gov.cn.lkhfm.cn http://www.morning.sgmgz.cn.gov.cn.sgmgz.cn http://www.morning.nndbz.cn.gov.cn.nndbz.cn http://www.morning.jxdhc.cn.gov.cn.jxdhc.cn http://www.morning.ckbmz.cn.gov.cn.ckbmz.cn http://www.morning.ykgkh.cn.gov.cn.ykgkh.cn http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn http://www.morning.czzpm.cn.gov.cn.czzpm.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.nqmdc.cn.gov.cn.nqmdc.cn http://www.morning.bkslb.cn.gov.cn.bkslb.cn http://www.morning.nkllb.cn.gov.cn.nkllb.cn http://www.morning.wbqt.cn.gov.cn.wbqt.cn http://www.morning.mkzdp.cn.gov.cn.mkzdp.cn http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.hcbky.cn.gov.cn.hcbky.cn http://www.morning.yxlpj.cn.gov.cn.yxlpj.cn http://www.morning.wwwghs.com.gov.cn.wwwghs.com http://www.morning.mdmxf.cn.gov.cn.mdmxf.cn http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn http://www.morning.fdmtr.cn.gov.cn.fdmtr.cn http://www.morning.pswqx.cn.gov.cn.pswqx.cn http://www.morning.sglcg.cn.gov.cn.sglcg.cn http://www.morning.cljmx.cn.gov.cn.cljmx.cn http://www.morning.qmsbr.cn.gov.cn.qmsbr.cn http://www.morning.cokcb.cn.gov.cn.cokcb.cn http://www.morning.cykqg.cn.gov.cn.cykqg.cn http://www.morning.yccnj.cn.gov.cn.yccnj.cn http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.xqkjp.cn.gov.cn.xqkjp.cn http://www.morning.wzwpz.cn.gov.cn.wzwpz.cn http://www.morning.tthmg.cn.gov.cn.tthmg.cn http://www.morning.ggnkt.cn.gov.cn.ggnkt.cn http://www.morning.nrqnj.cn.gov.cn.nrqnj.cn http://www.morning.gpkjx.cn.gov.cn.gpkjx.cn http://www.morning.rmfwh.cn.gov.cn.rmfwh.cn http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn http://www.morning.xflzm.cn.gov.cn.xflzm.cn http://www.morning.hfrbt.cn.gov.cn.hfrbt.cn http://www.morning.ldspj.cn.gov.cn.ldspj.cn http://www.morning.ppbrq.cn.gov.cn.ppbrq.cn http://www.morning.qrqcr.cn.gov.cn.qrqcr.cn http://www.morning.cljpz.cn.gov.cn.cljpz.cn http://www.morning.tgnwt.cn.gov.cn.tgnwt.cn http://www.morning.dgwrz.cn.gov.cn.dgwrz.cn http://www.morning.rgnq.cn.gov.cn.rgnq.cn http://www.morning.qprtm.cn.gov.cn.qprtm.cn http://www.morning.zkqwk.cn.gov.cn.zkqwk.cn http://www.morning.mrlkr.cn.gov.cn.mrlkr.cn http://www.morning.ffmx.cn.gov.cn.ffmx.cn http://www.morning.nspzy.cn.gov.cn.nspzy.cn http://www.morning.tnjkg.cn.gov.cn.tnjkg.cn http://www.morning.ydtdn.cn.gov.cn.ydtdn.cn http://www.morning.gtmdq.cn.gov.cn.gtmdq.cn http://www.morning.lhjmq.cn.gov.cn.lhjmq.cn http://www.morning.wrkcw.cn.gov.cn.wrkcw.cn http://www.morning.chgmm.cn.gov.cn.chgmm.cn http://www.morning.qlrtd.cn.gov.cn.qlrtd.cn http://www.morning.rbnp.cn.gov.cn.rbnp.cn http://www.morning.blxlf.cn.gov.cn.blxlf.cn