From the course: Java Design Patterns: Behavioral Part 1

Unlock the full course today

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

Creating a mediator object

Creating a mediator object - Java Tutorial

From the course: Java Design Patterns: Behavioral Part 1

Start my 1-month free trial

Creating a mediator object

- [Instructor] Now let's refactor this app to use the mediator pattern to reduce the tight coupling. To do this, the first thing I need to do is create a mediator class. This mediator is going to act as a sort of middleman and handle all of the different things that need to be handled for this customer to buy something on the site. So I'm going to create a new Java class and I'm going to call it mediator. This class is going to have a field for each of the different classes needed for this process. So it's going to have a customer field which I'll call customer and it's going to have an ECommerceSite field which I'll call sites. And it's going to have a driver field which I'll call driver. Now I'm going to create a constructor for this class. So I'm going to do public mediator, and in the constructor I'm going to do customer equals new customer and I'm going to pass in the address, 123 Sunny Streets. Then I'm…

Contents