Chapter 9. Python Design Patterns II

This chapter carries on from the previous chapter by introducing several more design patterns. Once again, we'll cover the canonical examples as well as any common alternative implementations in Python. We'll be discussing:

  • The adapter pattern
  • The facade pattern
  • Lazy initialization and the flyweight pattern
  • The command pattern
  • The abstract factory pattern
  • The composition pattern

Adapter pattern

Unlike most of the patterns we reviewed in Chapter 8, the adapter pattern is designed to interact with existing code. We would not design a brand new set of objects that implement the adapter pattern. Adapters are used to allow two pre-existing objects to work together, even if their interfaces are not compatible. Like the keyboard ...

Get Python 3 Object Oriented Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.