课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Factory
- 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 will 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.