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 - Python Tutorial
From the course: Python: Design Patterns
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
-
-
-
-
-
(Locked)
Decorator1m 5s
-
(Locked)
Decorator example4m 43s
-
(Locked)
Solution: Decorator1m 55s
-
Proxy1m 22s
-
(Locked)
Proxy example5m 23s
-
(Locked)
Adapter48s
-
(Locked)
Adapter example6m 16s
-
(Locked)
Composite1m 21s
-
(Locked)
Composite example5m 25s
-
Solution: Composite1m 44s
-
(Locked)
Bridge1m 14s
-
(Locked)
Bridge example5m 31s
-
(Locked)
-
-
-