课程: Python: Design Patterns (2021)

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Proxy example

Proxy example

- [Instructor] Let's first define our Producer class. We expect it to be more resource-intensive when we're 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 print 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…

内容