From the course: Python: Design Patterns
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Abstract factory - Python Tutorial
From the course: Python: Design Patterns
Abstract factory
- [Instructor] As its name suggests, abstract factory builds on the factory pattern. Abstract factory is useful when its user expects to receive a family of related objects at a given time but doesn't have to know which family it is until runtime. Here is the scenario we'll be using. Well first build a pet factory whose concrete factories include dog factory and cat factory. Both dog and cat factories produce dogs and cats, as well as related products, such as dog food and cat food. In theory, our solution, abstract factory, consists of abstract factory, concrete factory, abstract product and concrete product. For the abstract factory, we use pet factory. For concrete factory, we use dog factory and cat factory. And finally, for the concrete products, we'll be creating dogs, the type of pet and dog food, and also cats and cat food. We implement our abstract factory without using inheritance because Python is a dynamically…