We’ve been focused on objects and their attributes and methods. Now, we’ll take a look at designing higher-level objects, the kind of objects that manage other objects—the objects that tie everything together. These are sometimes called Facade objects because they present a pleasant, easy-to-use facade over some underlying complexity.

Management objects

Most of the previous examples tend to model concrete ideas. Management objects are more like office managers; they don’t do the actual visible work out on the floor, but without them, there would be no communication between departments, and nobody would know what they are supposed to do (although, this can be true anyway if the organization is badly managed). Analogously, the attributes of a management class tend to refer to other objects that do the visible work; the behaviors of such a class delegate to those other classes at the right time, and pass messages between them.

A manager relies on composite design. We assemble a manager class by knitting other objects together. The overall behavior of the manager emerges from the interaction of objects. To an extent, a manager is also an adapter among the various interfaces.

Example

As an example, we’ll write a program that does a find-and-replace action for text files stored in a compressed archive file, either a ZIP archive or a TAR archive. We’ll need objects to represent the archive file as a whole and each individual text file (luckily, we don’t have to write these classes, as they’re available in the Python standard library). An overall manager object will be responsible for ensuring the following three steps occur:

  1. Unzipping the compressed file to examine each member
  2. Performing the find-and-replace action on text members
  3. Zipping up the new files with the untouched as well as changed members

Get hands-on with 1200+ tech skills courses.