O'Reilly logo

Learning Python Design Patterns by Gennadiy Zlobin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Building Factories to Create Objects

In object-oriented development terminology, a factory is a class for creating other objects. Usually this class has methods that accept some parameters and returns some type of object depending on the parameters passed.

In this chapter we will cover:

  • How to create a simple factory
  • What the Factory Method is, when to use it, and how to implement it for building a tool that can be connected to a variety of web resources
  • What the Abstract Factory is, when to use it, and how it is different from the Factory method pattern

So why should we bother ourselves with factories instead of using direct object instantiation?

  • Factories provide loose coupling, separating object creation from using specific class implementation. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required