Summary

In this chapter, we took a step back from the details of Python to look at the SOLID design principles. These considerations are fundamental to how a stateful object should be designed. The principles provide us a useful collection of ideas for structuring an object-oriented design. It seems most useful to consider the principles in the following order:

  • Interface Segregation: Build the smallest interface to each class, refactoring to split a big class definition into smaller pieces.
  • Liskov Substitution: Be sure that any subclass can replace the parent class; otherwise, consider a composition technique instead of inheritance.
  • Open/Closed: A class should be open to extension but closed to direct modification. This requires careful consideration of what extensions are sensible for a given class.
  • Dependency Inversion: A class shouldn't have a simple, direct dependency on another class. A class should be provided via a variable so a runtime configuration can change the class used.
  • Single Responsibility: This summarizes the objective of defining classes with a single, narrow purpose, so changes are confined to one or a very few classes.

These principles will be implicit in the following chapters. The next chapter, Chapter 16, The Logging and Warning Modules, will look at using the logging and warnings modules to create audit information as well as to debug. We'll look at designing for testability and how we use unittest and doctest in Chapter 17, Designing for Testability. Later chapters will look at the design of applications, packages, and the general concepts of producing high-quality software.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset