From the course: Python: Design Patterns

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Proxy example

Proxy example

- [Tutor] Let's first define our producer class. We expect it to be more resource intensive when we are trying to instantiate it. Here, being resource intensive means using more computing resources, such as memory or CPU. The producer class prints the messages shown here. There are two methods defined. The first one is printing the current status of the producer, stating, "Producer is working hard!" The second method prints a statement saying that the producer now has time to meet a guest. The goal here is not to bother the producer until the producer is available, because the producer is very expensive to instantiate. Next, let's define the proxy class. The proxy class is relatively less resource intensive when instantiated. That's why we use the proxy object as a middle person to handle the request for the producer until the producer becomes available. Let's see what happens in the proxy class. We have two attributes. One is occupied. The default value for that attribute is no. We…

Contents