What Is a Decorator in I.T. or DevOps?

Problem scenario
You have read about decorators in object-oriented programming and in Python. Is there a disambiguation of what a decorator is?

In object-oriented programming, inheritance allows for an object to change from its class at compile time (according to page 201 of Programming Interviews Exposed). In OOP, the decorator pattern is a structural design pattern (according to the inside of the front cover of Design Patterns) and is a way to modify an object in OOP at run-time (according to page 201 of Programming Interviews Exposed). The intent of a decorator is to dynamically extend an object's functionality (according to page 175 of Design Patterns). The decorator can also be known as a wrapper (according to page 175 of Design Patterns).

In Python you can do object-oriented programming. However a decorator in Python should be thought of something completely different. There are class decorators and function decorators in Python.

"A [function] decorator in Python is a function that takes another function as its argument, and returns yet another function." (This quote was taken from https://towardsdatascience.com/how-to-use-decorators-in-python-by-example-b398328163b.)

"There's been a number of complaints about the choice of the name 'decorator' for this feature. The major one is that the name is not consistent with its use in the GoF book … The name 'decorator' probably owes more to its use in the compiler area -- a syntax tree is walked and annotated. It's quite possible that a better name may turn up." (This quote without the hyperlink was taken from https://www.python.org/dev/peps/pep-0318/.)

Leave a comment

Your email address will not be published. Required fields are marked *