> For the complete documentation index, see [llms.txt](https://appsecurity.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://appsecurity.gitbook.io/devops/ppc/ppc-langs/backend/python/patterns/factory.md).

# Factory

```python
class A(object):
   ...
   
class B(A):
   ...
   
class C(B):
   ...
   
// Not
a = A()
b = B()
c = C()

// Factory
class Factory:
   def create(self, what: str):
      if what == 'a':
         return A()
      if what == 'b':
         return B()
      ...
      
factory = Factory()
a = factory.create('a')
```
