Skip to main content

Posts

Showing posts from May, 2014

The Mediator Pattern

Mediator pattern is used to loosely couple object interaction. If objects are tightly coupled, resuability disappears and maintenance becomes harder. A real life scenario will explain the pattern the best. Think about an airport control tower. It's task is to moderate the flight landings. If many aircrafts arrive simultaneously, only one can land at a time and the rest have to stay out from landing until signaled by the tower. This behavior exactly matches that of the mediator pattern. The aircrafts don't communicate with each other but yet they communicate through the control tower so that they can avoid disaster. The C++ code simulating the landing of planes, helicopters and private jets at an airport is simulated in this code. Assume only one airstrip. The output: Mediator Will Take Over Landing Plane Landing 1 Heli Out of the way... 2 Jet Out of the way... 3 Jet Out of the way... 4 Mediator Will Take Over Landing Heli Out of the way... 2 Jet Landing 3 Jet Ou