From the course: Java Design Patterns: Structural
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution:The Façade pattern - Java Tutorial
From the course: Java Design Patterns: Structural
Solution:The Façade pattern
(upbeat music) - [Instructor] Let's take a look at my solution to the exercise. Yours might look a bit different to mine and that's fine. So I've created a new class called CarFacade. This has a single method called drive. I've moved all of the codes that was previously in the car class in the main method into here. So, all of the car components are now created in this method, and I'm calling all the same methods as before. Then in my car class, instead of having all this code in the main method, I'm just creating a new CarFacade object and calling the drive method I created. If I run the app again now, I can look at the console and see that I've got exactly the same output as before.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.