O'Reilly logo

Learning Python Design Patterns by Gennadiy Zlobin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementation in Python

Let's write our own example. Imagine that in our application we want to get the current temperature in a city. We had explored a range of available APIs for that and decided to use the openweathermap.org resource. It seems like a complicated procedure—a client makes a request to the API, parses it, retrieves necessary data, and converts from Kelvin to Celsius. This increases the complexity of the application. An end user would be happy to call only one method to get the current temperature. So, we can hide all of the intricacies of getting the weather condition behind the facade, providing only one function as the interface for the facade.

Let's build the first component of our complex system. The WeatherProvider class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required