From the course: Python: Design Patterns (2021)
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Abstract factory example - Python Tutorial
From the course: Python: Design Patterns (2021)
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…