Mastering Python Design Patterns
eBook - ePub

Mastering Python Design Patterns

A guide to creating smart, efficient, and reusable software, 2nd Edition

Kamon Ayeva, Sakis Kasampalis

Buch teilen
  1. 248 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Mastering Python Design Patterns

A guide to creating smart, efficient, and reusable software, 2nd Edition

Kamon Ayeva, Sakis Kasampalis

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Exploit various design patterns to master the art of solving problems using Python

Key Features

  • Master the application design using the core design patterns and latest features of Python 3.7
  • Learn tricks to solve common design and architectural challenges
  • Choose the right plan to improve your programs and increase their productivity

Book Description

Python is an object-oriented scripting language that is used in a wide range of categories. In software engineering, a design pattern is an elected solution for solving software design problems. Although they have been around for a while, design patterns remain one of the top topics in software engineering, and are a ready source for software developers to solve the problems they face on a regular basis. This book takes you through a variety of design patterns and explains them with real-world examples. You will get to grips with low-level details and concepts that show you how to write Python code, without focusing on common solutions as enabled in Java and C++. You'll also fnd sections on corrections, best practices, system architecture, and its designing aspects. This book will help you learn the core concepts of design patterns and the way they can be used to resolve software design problems. You'll focus on most of the Gang of Four (GoF) design patterns, which are used to solve everyday problems, and take your skills to the next level with reactive and functional patterns that help you build resilient, scalable, and robust applications. By the end of the book, you'll be able to effciently address commonly faced problems and develop applications, and also be comfortable working on scalable and maintainable projects of any size.

What you will learn

  • Explore Factory Method and Abstract Factory for object creation
  • Clone objects using the Prototype pattern
  • Make incompatible interfaces compatible using the Adapter pattern
  • Secure an interface using the Proxy pattern
  • Choose an algorithm dynamically using the Strategy pattern
  • Keep the logic decoupled from the UI using the MVC pattern
  • Leverage the Observer pattern to understand reactive programming
  • Explore patterns for cloud-native, microservices, and serverless architectures

Who this book is for

This book is for intermediate Python developers. Prior knowledge of design patterns is not required to enjoy this book.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Mastering Python Design Patterns als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Mastering Python Design Patterns von Kamon Ayeva, Sakis Kasampalis im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Ciencia de la computación & Programación en Python. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Microservices and Patterns for the Cloud

Traditionally, developers working on building a server-side application have been using a single code base and implementing all or most functionalities right there, using common development practices such as functions and classes, and design patterns such as the ones we have covered in this book so far. But, with the evolution of the IT industry, economic factors, and pressure for fast times to market and returns on investment, there is a constant need to improve the practices of engineering teams and ensure more reactivity and scalability with servers, service delivery, and operations. We need to learn about other useful patterns, not only object-oriented programming ones. In this chapter, we will cover the last part of our exploration, focused on Modern Architecture-style design patterns.
One of the main additions to the catalog of patterns for engineers in recent years has been the Microservice Architecture pattern or Microservices. The idea is that we can build an application as a set of loosely coupled, collaborating services. In this architectural style, an application might consist of services such as the order management service, the customer management service, and so on. Services can be developed and deployed independently of one another.
Moreover, increasing numbers of applications are deployed in the cloud (AWS, Azure, Google Cloud, Digital Ocean, Heroku, and so on) and must be designed upfront with this type of environment and its constraints in mind. A number of patterns have emerged to help us deal with these new aspects of our work. Even the engineering teams, ways of working have evolved, hence the DevOps teams and roles we now have in many software development and production organizations. There are many of these cloud architecture related patterns, but we choose to focus on a few ones related to Microservices: Retry, Circuit Breaker, and Cache-Aside. There are many of these cloud architecture related patterns, but we choose to focus on a few ones related to Microservices: Retry, Circuit Breaker, Cache-Aside, and Throttling.
In this chapter, we will discuss the following patterns:
  • The Retry pattern
  • The Circuit Breaker pattern
  • The Cache-Aside pattern
  • The Throttling pattern

The Microservices pattern

Before Microservices, developers of an application have been using a single code base for implementing all functionalities. For example, the front-end UI that includes forms, buttons, and specialized JavaScript code for interactions and effects, the application logic that handles all the passage of data between the UI and the database, and another application logic that, based on triggers or scheduling, does some asynchronous actions behind the scenes, such as sending email notifications. Even the administration UI, as in a Django-based application, would be inside the same application.
For this way of building an application, we talk about the Monolith model or using a Monolithic architecture.
There is a cost to the Monolithic model of application development. Here are some disadvantages:
  • Since it uses a single code base, the development team has to work on maintaining the whole code base simultaneously
  • It is more difficult to organize testing and reproduce and fix bugs
  • Tests and deployments become difficult to manage as the application and its user base grows and its constraints increase
With the Microservice pattern or Microservices, an application might consist of services such as the order management service, the customer management service, and so on. And, services can be developed and deployed independently of one another.

Real-world examples

When looking for examples, I found Eventuate™ (http://eventuate.io) which is a platform for developing asynchronous microservices. It solves the distributed data management problems inherent in a microservice architecture, enabling you to focus on your business logic.
eShopOnContainers is one of the Application Architecture reference applications from the
.NET Foundation (https://github.com/dotnet-architecture). It is described as an easy-to-get-started sample reference microservice and container-based application.
We can also cite Serverless architecture/computing, which shares some of the characteristics of microservices. Its main particularity is that there is no provision of server resources for running and operating things. Basically, you split your application at an even more granular level (using functions), and you use serverless hosting vendors to deploy the services. What makes this model attractive is that, with these providers (the big three players being AWS Lambda, Google Cloud Functions and Azure Functions), in theory, you only pay for the use involved (the execution of the functions).

Use cases

We can think of several use cases where microservices offer a clever answer. We can use a microservices architecture-based design every time we are building an application that has at least one of the following characteristics:
  • There is a requirement to support different clients, including desktop and mobile
  • There is an API for third parties to consume
  • We have to communicate with other applications using messaging
  • We serve requests by accessing a database, communicating with other systems, and returning the right type of response (JSON, XML, HTML or even PDF)
  • There are logical components corresponding to different functional areas of the application

Implementation

Let's briefly talk about software installation and application deployment in the Microservices world. Switching from deploying a single application to deployments of many small services means that the number of things that need to be handled increases exponentially. While you might have been fine with a single application server and few runtime dependencies, when moving to microservices, the number of dependencies will increase drastically. For example, one service could benefit from the relational database while the other would need ElasticSearch. You may need a service using MySQL and another one using the Redis server. So, using the microservices approach also means you need to use Containers.
Thanks to Docker, things are getting easier, since we can run those services as containers. The idea is that your application server, dependencies and runtime libraries, compiled code, configurations, and so on, are inside those containers. And then, all you have to do is run services packed as containers and make sure that they can communicate with each other.
You can implement the Microservices pattern, for a web app or an API, by directly using Django or Flask. However, for our examples, we are going to use a specialized microservices framework called Nameko (https://nameko.readthedocs.io).
According to their official website, Nameko is described as follows:
A microservices framework for Python that lets service developers concentrate on application logic and encourages testability.
Nameko has RPC over AMQP built in, allowing easy communication between the services. It also has a simple interface for HTTP requests.
Nameko and Flask: For writing Microservices that expose an HTTP endpoint, it is recommended that you use a more appropriate framework, such as Flask. To call Nameko methods over RPC using Flask, you can use flask_nameko, a wrapper built...

Inhaltsverzeichnis