Design Principles and Patterns

There are a number of considerations for object-oriented design. In this chapter, we'll take a step back from the details of the Python language to look at a few general principles. These principles provide fundamental guidance on how to design stateful objects. We'll look at concrete applications of the principles in Python.

The general approach we'll follow is defined by the SOLID design principles, which are as follows:

  • Single Responsibility
  • Open/Closed
  • Liskov Substitution
  • Interface Segregation
  • Dependency Inversion

While the principles have a clever mnemonic, we won't cover them in this order. The Interface Segregation Principle (ISP) seems to be the most helpful for decomposing a complex problem into individual class definitions. Most of the remaining principles help to refine the features of class definitions. The Single Responsibility Principle (SRP) seems a little less focused than the others, making it more useful as a summary than a starting point. For more information, see http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod for the original concepts. The linked site also includes a number of additional concepts. Our purpose in this book is to provide some Pythonic context to these principles. In this chapter, we will cover the following topics:

  • The SOLID design principles
  • SOLID principle design test
  • Building features through inheritance or composition
  • Parallels between Python and libstdc++
..................Content has been hidden....................

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