Please cite this article in press as: Cacho, N., et al., Blending design patterns with aspects: A quantitative study. J. Syst. Software (2014), http://dx.doi.org/10.1016/j.jss.2014.08.041 ARTICLE IN PRESS G Model JSS-9372; No. of Pages 23 The Journal of Systems and Software xxx (2014) xxx–xxx Contents lists available at ScienceDirect The Journal of Systems and Software j ourna l ho mepage: www.elsevier.com/locate/jss Blending design patterns with aspects: A quantitative study Nelio Cacho a, , Claudio Sant’anna b , Eduardo Figueiredo c , Francisco Dantas d , Alessandro Garcia e , Thais Batista f a Campus Universitario Lagoa Nova, Federal University of Rio Grande do Norte, Natal, RN 59078-970, Brazil b Federal University of Bahia, Brazil c Federal University of Minas Gerais, Brazil d State University of Rio Grande do Norte, Brazil e Pontifical Catholic University of Rio de Janeiro, Brazil f Federal University of Rio Grande do Norte, Brazil a r t i c l e i n f o Article history: Received 13 February 2014 Received in revised form 15 July 2014 Accepted 26 August 2014 Available online xxx Keywords: Design patterns Aspect-oriented programming Composability Empirical studies Metrics a b s t r a c t Design patterns often need to be blended (or composed) when they are instantiated in a software system. The composition of design patterns consists of assigning multiple pattern elements into overlapping sets of classes in a software system. Whenever the modularity of each design pattern is not preserved in the source code, their implementation becomes tangled with each other and with the classes’ core respon- sibilities. As a consequence, the change or removal of each design pattern will be costly or prohibitive as the software system evolves. In fact, composing design patterns is much harder than instantiating them in an isolated manner. Previous studies have found design pattern implementations are naturally cross- cutting in object-oriented systems, thereby making it difficult to modularly compose them. Therefore, aspect-oriented programming (AOP) has been pointed out as a natural alternative for modularizing and blending design patterns. However, there is little empirical knowledge on how AOP models influence the composability of widely used design patterns. This paper investigates the influence of using AOP models for composing the Gang-of-Four design patterns. Our study categorizes different forms of pattern com- position and studies the benefits and drawbacks of AOP in these contexts. We performed assessments of several pair-wise compositions taken from 3 medium-sized systems implemented in Java and two AOP models, namely, AspectJ and Compose*. We also considered complex situations where more than two patterns involved in each composition, and the patterns were interacting with other aspects implemen- ting other crosscutting concerns of the system. In general, we observed two dominant factors impacting the pattern composability with AOP: (i) the category of the pattern composition, and (ii) the AspectJ idioms used to implement the design patterns taking part in the composition. © 2014 Elsevier Inc. All rights reserved. 1. Introduction A design pattern is a repeatable solution to a recurring soft- ware design problem (Gamma et al., 1995). Software patterns first became popular with the publication of the Gang-of-Four (GoF) catalogue of design patterns (Gamma et al., 1995). Even though design patterns have been widely used in mainstream software projects, their modular implementation still imposes deep con- cerns to software engineers (Garcia et al., 2005; Hannemann and Kiczales, 2002). A design pattern (Gamma et al., 1995) assigns roles to their participant classes in a system, and each role defines the functionality of the participants in the pattern context. For instance, Corresponding author. Tel.: +55 84 32153814. E-mail address: neliocacho@gmail.com (N. Cacho). Observer and Subject are the two roles defined by the Observer design pattern (Gamma et al., 1995). These roles are assigned to the participant classes being affected by the pattern instance. The programming mechanisms, such as inheritance, are used to imple- ment these assignments. Ideally, the implementation of pattern roles should be localized, so that it is easy to recognize, change and remove it as the software system evolves. A key difficulty in applying design patterns stems from the fact they often need to be blended (or composed) when they are instan- tiated in a software system (Gamma et al., 1995; Zimmer, 1995). The composition of design patterns consists of assigning multiple pat- tern elements into overlapping sets of classes in a program (Gamma et al., 1995; Zimmer, 1995). In this case, the roles of the multiple patterns are somehow composed with the core implementation of classes in a program. Their object-oriented implementations can be blended in different ways (Gamma et al., 1995; Zimmer, 1995), http://dx.doi.org/10.1016/j.jss.2014.08.041 0164-1212/© 2014 Elsevier Inc. All rights reserved.