Using Decorators to Improve Our Code

In this chapter, we will explore decorators and see how they are useful in many situations where we want to improve our design. We will start by first exploring what decorators are, how they work, and how they are implemented.

With this knowledge, we will then revisit concepts that we learned in previous chapters regarding general good practices for software design, and see how decorators can help us comply with each principle.

The goals of this chapter are as follows:

  • To understand how decorators work in Python
  • To learn how to implement decorators that apply to functions and classes
  • To effectively implement decorators, avoiding common implementation mistakes
  • To analyze how to avoid code duplication (the DRY principle) with decorators
  • To study how decorators contribute to separation of concerns
  • To analyze examples of good decorators
  • To review common situations, idioms, or patterns for when decorators are the right choice
..................Content has been hidden....................

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