Using aspects and annotations to separate application code from design patterns

Design patterns are an invaluable resource to generate effective design solutions. However, employing some of them can be cumbersome for some application classes when these are forced to mix domain- with pattern-related code. Indeed, for a number of design patterns, we view the code implementing the behaviour required by their roles as a snippet, or concern, which is not involved in the domain issues that a class is supposed to address. This paper proposes a methodology to obtain the behaviour described by some well-known design patterns, which allows better separation between domain and non-domain concerns through recourse to aspects and annotations. Indeed, application classes retain all the benefits that the design patterns are supposed to give them, while staying thoroughly separated from non-domain concerns. Moreover, fewer lines of code are needed to obtain a design pattern than in other approaches, and the propagation of changes to application code, caused by the introduction or removal of a design pattern, are greatly reduced.