Book Image

Mastering Python Design Patterns

By : Sakis Kasampalis
Book Image

Mastering Python Design Patterns

By: Sakis Kasampalis

Overview of this book

Table of Contents (23 chapters)
Mastering Python Design Patterns
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
The Factory Pattern
Index

Summary


In this chapter, you learned how to use the Proxy design pattern. We used the Proxy pattern to implement a surrogate of an actual class when we want to act before (or after) accessing it. There are four different Proxy types. They are as follows:

  • A remote proxy, which represents an object that lives in a remote location (for example, our own remote server or cloud service)

  • A virtual proxy to delay the initialization of an object until it is actually used

  • A protection/protective proxy, which is used to access control to an object that handles sensitive information

  • When we want to extend the behavior of an object by adding support such as reference counting, we use a smart (reference) proxy

In the first code example, we created a virtual proxy in a pythonic style, using decorators and descriptors. This proxy allows us to initialize object properties in a lazy manner.

Chip and PIN and bank checks are examples of two different proxies used by people every day. Chip and PIN is a protective...