How do AspectJ features compare with those of mixin-based inheritance?

0
Posted

How do AspectJ features compare with those of mixin-based inheritance?

0

Some features of AspectJ, such as introduction, are related to mixin-based inheritance. But, in order to support crosscutting, a core goal for AspectJ, AspectJ goes beyond mixin-based inheritance. Firstly, an aspect imposes behavior on a class, rather than a class requesting behavior from an aspect. An aspect can modify a class without needing to edit that class. This property is sometimes called reverse inheritance. Secondly, a single aspect can affect multiple classes in different ways. A single paint aspect can add different paint methods to all the classes that know how to paint, unlike mixin classes. So mixin-based inheritance doesn’t have the reverse inheritance property, and mixins affect every class that mixes them in the same. If I want to do something like SubjectObserverProtocol, I need two mixins, SubjectPartofSubjectObserverProtocol and ObserverPartof… In AspectJ, both halves of the protocol can be captured in a single aspect.

Related Questions