In addition to the answers already received on a specific platform, I would like to add a more general view. This question, in my opinion, is somehow related to the decision to choose a decorator template instead of inheritance (for example, @Component vs extends Component )
Some of the benefits of using decorators are:
1. Separation of interests:
The information inside decorators is declarative, it determines the behavior of the class, most likely it will not change over time and is used by the platform. The properties and fields of the class are class-specific data, will always be processed and often updated, and only make sense inside the class itself. These two types of data should not be mixed together.
2. Support for multiple modifications
Many languages prevent multiple inheritance due to the Diamond problem . On the other hand, one class can have several decorators for different purposes (for example, @Component and deprecated @RouteConfig )
Harry ninh
source share