Similar to Decorator functions we can define a decorator to be a class.

A decorator class has a special class method __call__(). This method is responsible for supporting a case when an object is called. The advantage of decorator class over function is they bring the OOP feature such as inherirtance etc.

In the below code snippet the the decorated function is assigned to the self.func i.e. to the decorator. The decorator class itself calls the decorated function.

Passing a message to the decorator class. Here the message is passed from the LogDecorator and initailised in the class constructor.

The calling method is accessible in the __call__() method.