网站域名重定向怎么做万网ip
2026/4/18 12:56:28 网站建设 项目流程
网站域名重定向怎么做,万网ip,网站推广每天必做的流程,兰溪网站建设公司中介者是一种行为设计模式#xff0c; 让程序组件通过特殊的中介者对象进行间接沟通#xff0c; 达到减少组件之间依赖关系的目的。 中介者能使得程序更易于修改和扩展#xff0c; 而且能更方便地对独立的组件进行复用#xff0c; 因为它们不再依赖于很多其他的类。 使用示…中介者是一种行为设计模式 让程序组件通过特殊的中介者对象进行间接沟通 达到减少组件之间依赖关系的目的。中介者能使得程序更易于修改和扩展 而且能更方便地对独立的组件进行复用 因为它们不再依赖于很多其他的类。使用示例 中介者模式在 Python 代码中最常用于帮助程序 GUI 组件之间的通信。 在 MVC 模式中 控制器是中介者的同义词。from__future__importannotationsfromabcimportABCclassMediator(ABC): The Mediator interface declares a method used by components to notify the mediator about various events. The Mediator may react to these events and pass the execution to other components. defnotify(self,sender:object,event:str)-None:passclassConcreteMediator(Mediator):def__init__(self,component1:Component1,component2:Component2)-None:self._component1component1 self._component1.mediatorself self._component2component2 self._component2.mediatorselfdefnotify(self,sender:object,event:str)-None:ifeventA:print(Mediator reacts on A and triggers following operations:)self._component2.do_c()elifeventD:print(Mediator reacts on D and triggers following operations:)self._component1.do_b()self._component2.do_c()classBaseComponent: The Base Component provides the basic functionality of storing a mediators instance inside component objects. def__init__(self,mediator:MediatorNone)-None:self._mediatormediatorpropertydefmediator(self)-Mediator:returnself._mediatormediator.setterdefmediator(self,mediator:Mediator)-None:self._mediatormediator Concrete Components implement various functionality. They dont depend on other components. They also dont depend on any concrete mediator classes. classComponent1(BaseComponent):defdo_a(self)-None:print(Component 1 does A.)self.mediator.notify(self,A)defdo_b(self)-None:print(Component 1 does B.)self.mediator.notify(self,B)classComponent2(BaseComponent):defdo_c(self)-None:print(Component 2 does C.)self.mediator.notify(self,C)defdo_d(self)-None:print(Component 2 does D.)self.mediator.notify(self,D)if__name____main__:# The client code.c1Component1()c2Component2()mediatorConcreteMediator(c1,c2)print(Client triggers operation A.)c1.do_a()print(\n,end)print(Client triggers operation D.)c2.do_d()输出Client triggers operation A. Component 1 does A. Mediator reacts on A and triggers following operations: Component 2 does C. Client triggers operation D. Component 2 does D. Mediator reacts on D and triggers following operations: Component 1 does B. Component 2 does C.可以看出是让中介去写触发之后的逻辑链条。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询