From the course: Python: Design Patterns

Unlock this course with a free trial

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

Factory

Factory

- [Narrator] Factory encapsulates object creation. That is factory is an object specializing in creating other objects. The factory pattern is useful, especially when you're not sure about what type of objects you'll be needing eventually in your system. Another possibility is that your application needs to decide on what class to use at runtime. Here is a scenario we'll be using in our coding exercise. Your pet shop was only selling dogs, but now, you need to sell cats too. Therefore, your system needs to be able to handle cats as well as dogs. It's supposed to show how each of the pets you sell speaks.

Contents