课程: Python: Design Patterns (2021)

今天就学习课程吧!

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

Abstract factory example

Abstract factory example

- [Instructor] We'll start with the dog object that our concrete factory will return. Let's first define the dog class to instantiate the dog object. It has our favorite speak method. Next is a dog factory, and this is our concrete factory that returns two objects. The first object we're returning is a dog object and the second one is a dog food object. Let's add some internal documentation by saying here, returns, dog object, returns, a dog food object. Now, let's complete this code by typing return, the name of the class, dog, and parenthesis. And then we'll be returning the dog food string object. Type return, double quotes, dog food. Please note that our concrete products are the dog object and dog food. Unlike the factory pattern that creates one object, our dog factory produces a group of two related items, dog and dog food, in the context of the abstract factory pattern. The next class is the pet store class…

内容