From the course: Python: Design Patterns

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

Abstract Factory example

Abstract Factory example - Python Tutorial

From the course: Python: Design Patterns

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 the DogFactory, 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 DogFactory produces a group of two related items, Dog and Dog Food, in the context of the abstract factory pattern. The next class is the PetStore class that will act as our abstract factory. The first attribute of the PetStore…

Contents