Broker Mode Python

Source: Internet
Author: User


Class Infantry (object): Def __init__ (self, Mediator, name): Self.name = name Self.mediator = Mediator  def send (self, msg): Self.mediator.send (msg, self) def notify (self, msg): Print Self.name +        "Get infomation:" + msgclass Airforce (object): Def __init__ (self, Mediator, name): Self.name = Name        Self.mediator = Mediator def send (self, msg): Self.mediator.send (msg, self) def notify (self, msg):  Print Self.name + "Get infomation:" + msgclass Mediator (object): Soliders = [] def send (self, MSG, Solider): For S in self.soliders:if s! = solider:s.notify (msg) def register (SEL F, Solider): Self.soliders.append (solider) m = Mediator () T1 = Infantry (M, "Infantry-1") t2 = airfor CE (M, "AirForce-1") t3 = Airforce (M, "AirForce-2") m.register (T1) m.register (T2) m.register (T3) t1.send ("I have Foun D killer ") T2.send (" LooK at him ") t3.send (" Be Careful ") 


Broker Mode Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.