From the course: Python: Advanced Design Patterns
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Mediator example - Python Tutorial
From the course: Python: Advanced Design Patterns
Mediator example
- [Instructor] Mediator consists of the Mediator, Concrete Mediator, Colleague, and Concrete Colleague classes. The Concrete Colleague class inherits from the Colleague class while the Concrete Mediator class inherits from the Mediator class. Let's start by reviewing the Colleague class. It has a constructor that allows a Colleague object to store its own ID, and the Mediator it is assigned to. So, the ID is stored here, the Mediator is being stored there. Next is a getter method, right here, used to retrieve an ID of a Colleague object. The send and receive methods are skeleton methods meant to be overridden by the Concrete Colleague class. Let's move on to the Concrete Colleague class now. As I told you already, it overrides the send and receive methods. Right here, send and receive. The send method prints a statement indicating which colleague object is sending a message, as you can see here. Then, it should invoke a distribute method on a Mediator associated with itself. The code…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.