Behavioral Patterns  «Prev  Next»
Lesson 13 Course project, part 6
ObjectiveWrite a Mediator Class for the Course Project

Write a Mediator Class for the Course Project

For this part of the course project, you will be incorporating the Mediator pattern into your traffic flow system. The class that you develop will coordinate the intersection and the four traffic lights.
This class will be responsible for queuing requests and making sure that each light is green for a minimum amount of time.

This diagram illustrates how the traffic lights will interfact with the Mediator.

The Mediator design pattern enables decoupling of objects by introducing a layer in between the various objects so that the interaction between objects can happen by means of the layer. In an enterprise application where we have a large number of classes, the complexity also increases as the size of the project increases. The business logic might be spread across several classes and there will be interaction between classes. If we draw an interaction line between these classes where we have interaction, it will become difficult to decipher what is going on. Before application of the Mediator pattern, there exists complex interaction between objects, and this creates dependency and tighter coupling. Our objective is to achieve loose coupling, and we want to reduce dependency as much as possible while increasing reusability.

Signal Mediator Class - Exercise

In this exercise, you will write a SignalMediator class for the intersection that manages the four lights.
Signal Mediator Class - Exercise