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 - 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
-
-
-
-
(Locked)
Factory57s
-
Factory example7m 37s
-
Solution: Factory2m 37s
-
(Locked)
Abstract Factory1m 46s
-
(Locked)
Abstract Factory example5m 57s
-
(Locked)
Singleton1m 39s
-
Singleton example7m 17s
-
(Locked)
Solution: Singleton2m 20s
-
(Locked)
Builder2m 3s
-
(Locked)
Builder example5m 59s
-
(Locked)
Prototype1m 30s
-
(Locked)
Prototype example7m 18s
-
(Locked)
-
-
-
-