From the course: Complete Guide to Java Design Patterns: Creational, Behavioral, and Structural
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Challenge: The Mediator pattern - Java Tutorial
From the course: Complete Guide to Java Design Patterns: Creational, Behavioral, and Structural
Challenge: The Mediator pattern
In this challenge, you'll be updating a traffic light control system to use the mediator pattern. At the moment, there are a couple of classes to look at. The first is this PedestrianCrossingLights class. So this can be two colors, either red or green. Initially, the color field is set to red, and then there are two methods one to set the color to red and the other to set it to green. Then there's the TrafficLight class. A traffic light can be either red, amber, or green. And there are methods to set each of these colors, too. But when the light changes to red or green, it also needs to change the pedestrian light color. For example, when the traffic light is set to red, it sets the color of this light to reds and then it prints out a message saying traffic light is red and then it says pedestrianCrossingLights.changeToGreen. And in the changeToGreen method, for example, it first sets the pedestrian crossing light to red and then it changes the color of this light to green. This does…
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
(Locked)
Understand abstract factories3m 7s
-
(Locked)
Recognize where to use abstract factories3m 53s
-
(Locked)
Create factories for families of objects6m 4s
-
(Locked)
Implement the complete Abstract Factory pattern6m 1s
-
(Locked)
Challenge: The Abstract Factory pattern1m 36s
-
(Locked)
Solution: The Abstract Factory pattern2m 34s
-
(Locked)
-
-
(Locked)
Understand the Chain of Responsibility pattern1m 23s
-
(Locked)
Recognize where to use the Chain of Responsibility pattern2m 35s
-
(Locked)
Implement a successor chain4m 49s
-
(Locked)
Challenge: The Chain of Responsibility pattern1m 48s
-
(Locked)
Solution: The Chain of Responsibility pattern3m 59s
-
(Locked)