A decorator is a structural design pattern that enables adding new functionality to existing objects without altering their structure. This is achieved by wrapping the original object with a new class that enhances its behavior.
In programming languages like Python, decorators are often used to modify the behavior of functions or methods. For example, a logging decorator can be applied to a function to log its execution time without changing the function's code.
Here’s a simple example: if you have a function that returns a greeting, you can use a decorator to print a message before and after the greeting is displayed, enhancing the user experience without modifying the original function.