From the course: C++ Design Patterns: Structural

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: Hide complexity with a facade

Solution: Hide complexity with a facade - C++ Tutorial

From the course: C++ Design Patterns: Structural

Solution: Hide complexity with a facade

(bright music) - [Instructor] We have our WeatherFacade class which wraps all three web services, WorldWeatherAPI, FreeWeather, and RealtimeWeatherService. The class exposes a single public method current weather, which takes a location as an argument and returns a string. The method internally cause the web services stores their results in three different variables and combines the relevant weather data into a single string. I used the string stream object to easily build the string. Finally, I return the generated string from the method. Using this new facade class is extremely easy. So here's the main function. I just create an instance of this class and call the current weather method. The output of this code is the same as before. The goal of simplifying the design and making it easier to interact with the weather API has been achieved by using the facade design pattern. Now you know how to use the facade design pattern in…

Contents