Intermediary Mode: Encapsulate a series of object interactions with an intermediary object. The intermediary makes the objects do not need to be explicitly referenced to each other, so that the coupling is loose and the interaction between them can be changed independently.
AverageApplicationWhen a group of objects communicate in a well-defined but complex manner.
Advantages: Reduces the coupling of each module.
Disadvantages: The intermediary objects are easy to become complex and huge.
# Encoding = UTF-8 ## by Panda # intermediary mode def printinfo (Info): Print Unicode (Info, 'utf-8 '). encode ('gbk') # Abstract intermediary class mediator (): def send (self, message, colleague): pass # Abstract colleague class colleague (): mediator = none def _ init _ (self, mediator): Self. mediator = mediator # A colleague class concretecolleague (colleague): name = ''def _ init _ (self, name, mediator): Self. name = Name colleags. _ init _ (self, mediator) def send (self, message): Self. mediator. send (message, self) def every Y (self, message): printinfo ('% s) Get the recipient's message: % s' % (self. name, message) # The mediator class concretemediator (mediator): name = ''colleague1 = none colleague2 = none def _ init _ (self, name): Self. name = Name def send (self, message, colleague): If colleague = self. colleague1: Self. colleague2.notify (Message) else: Self. colleague1.y y (Message) def clientui (): mediator = concretemediator ('United Nations ') USA = concretecolleague ('America', mediator) mediator. colleague1 = USA Iraq = concretecollegou ('Iraqi ', mediator) mediator. colleague2 = Iraq USA. send ('nuclear weapons are not allowed to be developed, or war should be launched ') Iraq. send ('we do not have nuclear weapons and are not afraid of aggression ') returnif _ name _ =' _ main _ ': clientui ();
Class Diagram: