From the course: Java Design Patterns: Behavioral Part 1

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Challenge: The Mediator pattern

Challenge: The Mediator pattern - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 1

Start my 1-month free trial

Challenge: The Mediator pattern

(bright upbeat music) - [Instructor] Let's have a look at our next exercise. In this one, you're going to be refactoring an air-traffic control app using the mediator pattern to remove tight coupling. So let's have a look at the code. In the main class, there is a main method which creates an object of type plane, and then cause a method called takeoff. Like the example in the previous videos, this looks fairly straightforward at first, but a closer look will show you that all of the classes are tightly coupled. If I look inside the plane class, it has fields for runway, planes in flight and planes on ground. So let's take a look at the takeoff method. This is making changes to each of these fields. If I wanted to add more planes, this would be difficult to do. How would they know about the planes in flight and planes on ground objects of the other planes? At the moment, this is too tightly coupled to extend the…

Contents