Summarize the concept explored in this chapter regarding when to use object-oriented programming in Python.

We'll cover the following


Here are some of the key points in this chapter:

  • When we have both data and behavior, this is the sweet spot for object-oriented design. We can leverage Python’s generic collections and ordinary functions for many things. When it becomes complex enough that we need to be sure that pieces are all defined together, then we need to start using classes.
  • When an attribute value is a reference to another object, the Pythonic approach is to allow direct access to the attribute; we don’t write elaborate setter and getter functions. When an attribute value is computed, we have two choices: we can compute it eagerly or lazily. A property lets us be lazy and do the computation just in time.
  • We’ll often have cooperating objects; the behavior of the application emerges from the cooperation. This can often lead to manager objects that combine behaviors from component class definitions to create an integrated, working whole.


In this chapter, we focused on identifying objects, especially objects that are not immediately apparent; objects that manage and control. Objects should have both data and behaviors, but properties can be used to blur the distinction between the two. The DRY principle is an important indicator of code quality, and inheritance and composition can be applied to reduce code duplication.

Get hands-on with 1200+ tech skills courses.