Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Composing Design Patterns:

A Scalability Study of Aspect-Oriented Programming


Nelio Cacho1,3 Claudio Sant’Anna2 Eduardo Figueiredo2
Alessandro Garcia1 Thais Batista3 Carlos Lucena2
1
Computing Department, Lancaster University, United Kingdom
2
Computer Science Department, Pontifical Catholic University of Rio de Janeiro – PUC-Rio, Brazil
3
Computer Science Department, Federal University of Rio Grande do Norte – UFRN, Brazil
{n.cacho, a.garcia}@lancaster.ac.uk,
{emagno,claudios,lucena}@inf.puc-rio.br, thais@ufrnet.br

ABSTRACT Recent systematic studies [9,12] have shown that a number of


Pattern composition has been shown as a challenge to applying design patterns involve crosscutting concerns in the relationship
design patterns in real software systems. One of the main between the pattern roles and participant classes in each instance
problems is that multiple design patterns in a system are not of the pattern. The pattern roles often crosscut several business
limited to affect only the application concerns. They also crosscut classes in a software system. OO abstractions are not able to
each other in multiple heterogeneous ways so that their separation localize these pattern-specific concerns and tend to lead to
and composition are far from being trivial. In this context, it is of programs with poor modularity attributes [9]. The situation is
paramount importance to systematically verify whether aspect- even worse in real OO designs; pattern implementations typically
oriented programming (AOP) supports improved composability of crosscut the implementations of other pattern roles as they need to
design patterns. This paper presents a systematic investigation on be composed. This means that pattern roles are scattered and
how AOP scales up to deal with modularization of pattern- tangled to each other and through the participant classes, which in
specific concerns in the presence of pattern interactions. We have turn leads to the pattern instances to get lost [21] or degenerate
made both qualitative and quantitative assessments of 62 pair- [5] in the system. Also this crosscutting phenomenon potentially
wise compositions taken from 3 medium-sized systems has negative impacts on quality attributes of both pattern-specific
implemented in Java and AspectJ programming languages. Our and application-specific implementations.
analysis has also included the evaluation of compositions In this context, it is of paramount importance to systematically
involving more than two patterns. The assessment was based on verify whether AOP approaches (such as [15]) support improved
four fundamental software attributes, namely separation of composability of design patterns. It requires an investigation on
concerns, coupling, cohesion, and conciseness. how AOP scales up to deal with modularization of crosscutting
concerns relative to pattern roles in the presence of pattern
Categories and Subject Descriptors interactions. To the best of our knowledge, there is no systematic
D.2.2 [Software Engineering]: Design Tools and Techniques - evaluation of the effects of AOP on pattern compositions. Up to
Object-oriented design methods; D.2.8 [Software Engineering]: now, qualitative and quantitative studies involving the
Metrics-Product metrics; D.3.3 [Programming languages]: “aspectization” of design patterns [9, 10, 11, 12] focused on the
Language Constructs and Features separation of a particular design pattern and its participant classes
in the application. Although these first assessments provided
General Terms initial interesting results, the implementation and evaluation of the
Design, Experimentation, Languages. pattern instances were isolated from each other. They were not
taken in the context of existing software systems where
Keywords interactions between pattern implementations are recurring and
intricate. This problem seriously constrains the extrapolation of
Design patterns, aspect-oriented programming, composability, the results and limits our understanding on how AO solutions
empirical studies, metrics. scale up to cope with realistic scenarios involving complex pattern
instances and different composition contexts. Hence, a number of
1. INTRODUCTION questions remain unaddressed:
Design patterns are present in every real system we build in order (i) does AOP promote improved pattern composability?
to assure stringent modularity principles, such as low coupling, (ii) to what extent separation of pattern roles is preserved in
high cohesion, conciseness, and separation of concerns. A design realistic contexts involving pattern compositions?
pattern assigns roles to their participant classes, which define the
(iii) what are the positive and negative influences of aspectized
functionality of the participants in the pattern context [11]. The
pattern compositions on fundamental software attributes, such
application of design patterns in complex systems is often a result
as coupling, cohesion, and conciseness?
of the composition of two or more pattern roles rather than their
(iv) what does happen in more intricate compositions involving
instantiations in an isolated manner. Their object-oriented (OO)
3 or more patterns? How much do the aspect-oriented
implementations can be composed in different ways [6, 23],
implementations scale in these cases?
ranging from a simple method invocation between the patterns’
roles to the sharing of one or more classes by the pattern roles.
To explore these issues, we have performed an empirical study pattern. Some operations that change a Colleague must trigger
where we have assessed OO and aspect-oriented (AO) solutions updates to the corresponding Mediator; in other words, the act of
that implement compositions of the Gang-of-Four (GoF) patterns. updating crosscuts one or more operation in each Colleague in the
It includes the quantitative and qualitative assessments of 62 pair- pattern [9]. Mediator is also usually a superimposed role.
wise compositions taken from 3 medium-sized systems
In this context, systematic studies have investigated the effects of
implemented in Java [13] and AspectJ [1] programming
AOP on the modularization of design patterns. Hannemann and
languages. Our analysis has also included the evaluation of
Kiczales (HK) [12] have undertaken a qualitative study in which
compositions involving more than two patterns. The assessments
they have developed and compared Java [13] and AspectJ [1]
were based on 4 basic modularity attributes, namely separation of
implementations of the 23 GoF patterns [6]. The basic idea was
concerns (SoC), coupling, cohesion, and conciseness. This paper
the identification of the common part of several patterns and the
also correlates our study findings with the results from previous
isolation of their implementations in aspectual modules. Some of
studies, contributing to an improved body of knowledge on the
these modules were defined as reusable aspects that are extended
scalability of AOP for addressing the crosscutting property of
in order to instantiate the pattern for a specific application. Our
patterns in a multitude of composition scenarios.
previous work [9] focused on the quantitative assessment of the
The remainder of this paper is organized as follows. Section 2 HK implementations for the GoF patterns. Both studies have used
presents our study setting. Section 3 presents the study results modularity attributes as assessment criteria.
with respect to the investigated modularity attributes. These
However, for each of the 23 patterns these initial studies used a
results are interpreted and discussed in Section 4, which also
very simple example that made use of the pattern. The pattern
points out some constraints of our study. Section 5 introduces
instances were not taken from realistic software systems. More
some related work. Section 6 includes some concluding remarks
importantly, AOP has not been assessed in the context of pattern
and future work.
compositions. The HK study alleged that 15 aspectized patterns
2. STUDY FORMAT had superior “composition transparency”. However, this property
only captured a narrow view of pattern composability; it is related
This section first puts our study in perspective of previous work
to the ease of composition between the general code of a single
(Section 2.1). It also describes our categorization defined for
pattern and their multiple instances [12]. There are additional
pattern compositions (Section 2.2), and the procedures and
studies (e.g. [16, 17]) related to the aspectization of GoF patterns,
metrics used to support our quantitative assessment (Section 2.3).
but they focus on some specific patterns. They also do not assess
2.1 Modularizing Design Patterns how AOP scale up to deal with crosscutting concerns in the
There are two kinds of pattern roles [12]: defining and presence of pattern interactions.
superimposed roles. A defining role defines a participant class
completely. In other words, classes playing a defining role have
2.2 Pattern Composition Categories
Pattern compositions involve the combination of their roles.
no functionality outside the pattern. The unique role of the Façade
Figure 1 shows an OO design slice of an OpenOrb-compliant
pattern [6] is an example of defining role. A superimposed role
middleware system [2] in which a number of GoF patterns are
can be assigned to participant classes that have functionality
used and combined to achieve the middleware requirements of
outside of the pattern. An example of superimposed role is the
high customizability and adaptability. In the Figure 1, each
Colleague role of the Mediator pattern [6], since a participant
number represents a specific pattern, and these numbers are
class playing this role usually has functionality not related to the
associated with methods and attributes. The number attachment
pattern. General-purpose design patterns, such as GoF patterns,
indicates that the associated method or attribute is part of the
exhibit crosscutting concerns [6,9]. For example, consider the
implementation of the corresponding pattern. For example, the
Mediator and Colleague roles that are defined in the Mediator
implementation of the Decorator pattern (represented by number
Legend
Decorator - 1 Proxy - 6 ConcreteBind
{abstract} ConcreteMetaInvocationHandler
Mediator - 2 State - 7
- successor : MetaInvocationHandler 9
Memento - 3 Template Method - 8 - nextHandler : Port 2
+ mediator : BindMediator
- bdstate : BindState 2
Observer - 4 Chain of Responsibility - 9 7
- running : BindState + handleRequest (Object[] args) : void 2, 9
Prototype - 5 - connected : BindState
5
+ setSuccessor (MetaInvocationHandler next) : void
9
- observers : HashSet 4 + getSuccessor () : MetaInvocationHandler
BindMediator + getTargetMethod (String method, Object[] args, Class oClass) : Method
+ getRealArgs (String method, Object[] args) : Object[]
+ makeRequest (String method, Object[] args) : Object 1,2,5,7
+ makeRequest (String method, Object[] args) : Object 1,2
+ rebind (Port newRecept) : void BindState
4,7
+ breakBind () : void
+ setNextHandler (Port nextHandler) : void
2 + rebind (Port recpt) : void
+ getNextHandler () : Port 7
DecoratorBind + breakBind () : void
+ addObserver (MetaObserver o) : void
{abstract} + clone () : Object 5
+ removeObserver (MetaObserver o) : void 4
# bind : BindMediator 1 + notifyObservers () : void
+ checkPreMethods (String method, Object[] args) : void
1,8 BindConnected BindRunning
+ checkPosMethods (String method, Object[] args) : void Interface
Port - bind : BindMediator
+ makeRequest (String method, Object[] args) : Object 1,8
+ rebind (Port newRecept) : void {abstract} 7
+ rebind (Port recpt) : void + rebind (Port recpt) : void
1 7
+ breakBind () : void # bind : BindMediator 2 + breakBind () : void + breakBind () : void
- observers : HashSet 4 + clone () : Object 5 + clone () : Object 5
+ setName (String name) : void 4
+ getName () : String BankStub Bank
MetaBind + setMemento (CapturerMetaState meta) : void
3
+ createMemento () : CapturerMetaState
+ deposit (double value) : void + deposit (double value) : void
+ addObserver (MetaObserver o) : void
+ withdraw (double value) : void 2,6 + withdraw (double value) : void 6
+ checkPreMethods (String method, Object[] args) : void + removeObserver (MetaObserver o) : void 4
1,8 + balance () : double + balance () : double
+ checkPosMethods (String method, Object[] args) : void + notifyObservers () : void

Figure 1. An OO design slice of the OpenOrb component model [2]: tangling and scattering of pattern-related concerns
1) includes the attribute bind and affects several methods, such as Memento with Observer, and Prototype with Observer. For
makeRequest(), breakBind(), rebind(), checkPreMethods(), and example, the class Port belongs to both Memento and Observer
checkPosMethods(). implementations, but it has no method that contains code relative
An analysis of Figure 1 also makes it evident that most of the to both patterns.
pattern-related concerns are scattered over the system classes, as Method-level interlacing. Differently from class-level
commonly happens in realistic applications. The roles of the State interlacing, the implementations of patterns P1 and P2 have one
pattern affect various methods in the classes ConcreteBind, or more methods in common. Different pieces of code in these
BindConnected, and BindRunning. Pattern roles are also tangled methods are dedicated to implement roles of both P1 and P2.
with each other and with middleware-specific concerns. For Hence the pattern implementations are interlaced at the method
example, the methods rebind() and breakBind() in the class level. Both method- and class-level interlacing produce tangling
ConcreteBind implement middleware-specific functionalities, but of concerns, but at different levels of abstraction. Some examples
also incorporate code of the Observer and State patterns. In this of this kind of pattern composition appear in Figure 1: Mediator
context, there are different ways in which the patterns interact with CoR, and Mediator with Prototype. They can be easily
with each other. The pattern compositions vary from a simple detected in Figure 1 as the numbers of the patterns in the
method invocation between the patterns’ roles to the sharing of composition appear attached to a same method. For instance, the
one or more classes by the pattern roles. The pair-wise method ConcreteBind.makeRequest() is mostly dedicated to the
interactions of OO pattern implementations investigated in our implementation of the Mediator role. However, it also contains
study are classified in 4 categories as described in the following. code relative to the Prototype pattern.
Invocation-based composition. The implementations of the two Overlapping. The implementations of patterns P1 and P2 share
composed patterns, namely P1 and P2, are disjoint and they have one or more statements, attributes, methods, and classes. This
no class in common. The roles of P1 and P2 are only connected combination style is different from, for example, method-level
through one or more method calls. This is the simplest form of interlacing because here the shared elements are entirely part of
pattern composition. The combination of Chain of Responsibility roles in both patterns; in the previous case, the parts of the code in
(CoR) and Prototype is included in this category. Figure 1 the common method implementing the pattern roles are disjoint.
illustrates the realization of this combination for a middleware An example of class overlapping in Figure 1 is the combination of
implementation. Note that the CoR and Prototype roles are Decorator with Mediator: the interface BindMediator is part of
affecting different classes. Their composition is based only on a both pattern structures. It may be the case that we have a complete
call to the method ConcreteBind.makeRequest() (implementing overlapping in the sense that the implementation of a given
the Prototype pattern) within the method handleRequest() of the pattern is entirely contained by the other pattern. The Decorator
class ConcreteMetaInvocationHandler (participant of the CoR pattern, for instance, contains the implementation of Template
pattern). Method (Figure 1).
Class-level interlacing. The implementations of patterns P1 and 2.3 Assessment Procedures
P2 have one or more classes in common. The roles of P1 and P2 Our study has focused on the assessment of compositions
are implemented by different sets of methods and attributes in involving all the 23 GoF design patterns. We have used three
these shared classes. In other words, the involved patterns have medium-sized software systems as case studies: (1) an OpenOrb-
coinciding participant classes, but there is no common method or compliant middleware system [2], (2) a measurement tool [3], and
attribute implementing roles of both patterns. As a result, the (3) an agent-based application for supporting paper submission
pattern implementations have been interlaced (or tangled) at the and selection processes [7, 8]. These systems were selected for
class level. Examples of this composition category in Figure 1 are
Table 1. The Metrics Suite [07, 18]
Attributes Metrics Definitions
Concern Diffusion over Counts the number of classes and aspects whose main purpose is to contribute to the
Components (CDC) implementation of a concern and the number of other classes and aspects that access them.
Separation Concern Diffusion over Counts the number of methods and advices whose main purpose is to contribute to the
of Concerns Operations (CDO) implementation of a concern and the number of other methods and advices that access them.
Concern Diffusions over LOC Counts the number of transition points for each concern through the lines of code. Transition
(CDLOC) points are points in the code where there is a “concern switch”.
Counts the number of other classes and aspects to which a class or an aspect is linked. It
Coupling Between
considers elements declared in formal parameters, return types, throws declarations, and
Coupling Components (CBC)
local variables.
Number of Children (NOC) Counts how many children a class or aspect has.
Lack of Cohesion in Measures the lack of cohesion of a class or an aspect in terms of the amount of method and
Cohesion
Operations (LCOO) advice pairs that do not access the same instance variable.
Lines of Code (LOC) Counts the lines of code.
Number of Attributes(NOA) Counts the number of attributes of each class or aspect.
Size
Weighted Operations per Counts the number of methods and advices of each class or aspect and the number of its
Component (WOC) parameters.
several reasons. First, their OO implementations are largely based and size. The coupling, cohesion, and size metrics are extensions
on design patterns due to their requirements of maintainability, of traditional and OO metrics in order to be applied in a
evolvavility, and reusability. The second reason is the paradigm-independent way, and support the generation of
heterogeneity of the pattern compositions found in these systems. comparable results between Java and AspectJ solutions.The
Third, they encompass different characteristics, diverse domains, metrics suite also encompasses new metrics for measuring
and different degrees of complexity in terms of pattern instances separation of concerns. The separation of concerns metrics
and their compositional nature. The following subsections measure the degree to which a single concern in the system maps
describe how we have obtained and assessed the pattern to the design components (classes and aspects), operations
compositions. (methods and advices), and lines of code.

2.3.1 Selection and implementation of pattern Due to space limitation, the used metrics are briefly described in
compositions Table 1; an extensive explanation and justification about them are
out of the scope of this work and can be found at [7, 18]. Table 1
We have reengineered the existing Java implementations of the
presents a brief definition of each metric, and associates them with
first two systems with AspectJ in order to produce the AO
the attributes measured by each one. These metrics have already
versions of those systems. For the third case study, we have
been extensively used and proved to be useful quality indicators
reused both existing Java and AspectJ implementations [7, 8]. In
in several studies [4, 7-9, 11, 20]. We have applied the chosen
both OO and AO solutions, we have tried to maximize the
metrics to both Java and AspectJ versions. We analyzed the
separation of each pattern with respect to the second pattern in the
results, and also compared them with the results gathered in the
combination and to the application-specific concerns. Our
two main previous studies (Section 4.1).
intention with this approach was to make the pattern
implementation as modular as possible in order to facilitate the In the measurement process, the data was partially gathered by our
composition of it with different patterns. While implementing the own measurement tool [3]. It supports all the metrics, except the
AspectJ versions, we have also aimed at preserving the use of the metrics of separation of concerns (CDC, CDO, and CDLOC). The
original versions of the pattern implementations [12] as much as data collection of the separation of concerns metrics was preceded
possible in order to correlate the results of this study with by the shadowing of every class, interface and aspect in both
previous ones [9, 12]. However, due to each application’s implementations of the pattern compositions. Their code was
specificities, in some cases we needed to carry out minor shadowed according to the pattern roles that they implement. We
modifications in the original AspectJ implementations [12] while treated each design pattern as a concern in order to investigate its
trying to achieve the intended pattern modularization. Moreover, crosscutting structure in pattern compositions. After the
in other cases we needed to rely on a different AspectJ version shadowing, the data of the separation of concerns metrics (CDC,
because the application context required a specific pattern variant. CDO, and CDLOC) was manually collected. Due to space
As it will be mentioned through the paper, the aspectization of limitation, this paper focuses on the description of the more
some patterns was due to certain composition circumstances. It relevant results. The complete description of the data gathered is
should be reviewed as an unfavorable result for AspectJ solution. reported elsewhere [25].
A tally of 62 compositions was chosen in the 3 case studies. Most
of these compositions are documented through the GoF pattern 3. RESULTS
catalogue [6]. Each pattern participated at least in 2 compositions, This section presents the measurement results for the 62
and each composition category (Section 2.2) involved the compositions, which are grouped in the respective composition
minimum of 9 different composition instances. The measurement categories. For each category, we focus first on the presentation of
process was preceded by the isolation of each composition results related to separation of concerns. Afterwards, we show
instance from the application implementation so that we could how the aspectization of the pattern compositions impacted on the
perform the proper measurements. other software attributes. In order to illustrate the results, some
specific compositions are used as representatives in the following
In order to compare the two implementations of the compositions, subsections. The discussion about the interplay among all the
we had to ensure that both Java and AspectJ versions were results is concentrated in Section 4. Section 4 also discusses the
implementing the same functionalities. Therefore, some minor relationships between our study’s results and the conclusions
modifications were realized in the code of the patterns. Examples obtained in previous case studies (Section 2.1).
of such kinds of changes were: (i) to add or remove a functionality
– a method, a class or an aspect – in the aspect-oriented (or Graphics are used to represent the data gathered in the
object-oriented) implementation of the composed patterns in order measurement process. The graphic Y-axis presents the absolute
to ensure the equivalence between the two versions; we decided to values gathered by the metrics. Each pair of bars is attached to a
add or remove a functionality to the implementation by evaluating percentage value, which represents the difference between the AO
its relevance for the pattern implementation; and (ii) to ensure that and OO results. A positive percentage means that the AO
both versions were using the same coding styles due to the fine implementation was superior, while a negative percentage means
granularity of our metrics. that the AO implementation was inferior. These graphics support
an analysis of how both solutions for the pattern compositions
2.3.2 Measurement process affect the selected measures. There are two kinds of graphics: (i)
The quantitative assessment was based on the application of a the graphics for SoC measures, and (ii) the graphics for the
metrics suite [7, 18] to the 62 compositions. These metrics are coupling, cohesion, and size attributes. The first one shows how
useful to capture important modularity dimensions in the pattern each pattern was isolated in the pattern composition in terms of
compositions, namely separation of concerns, coupling, cohesion, the 3 SoC measures. The results shown in the other graphics were
gathered according to the entire composition point of view; that 3.2 Class-level interlacing
is, they represent the tally of metric values associated with all the For the 11 compositions investigated in this category, all AspectJ
classes and aspects involved in the pattern composition as a solutions have in general shown significant superiority in terms of
whole. SoC measures. The improvements come primarily of
disentangling the pattern concerns in the shared classes. The Java
3.1 Invocation-based composition implementations of those classes typically include significant code
For this category, 9 compositions were investigated. The AO
from both patterns in addition to the business-related concerns. As
solution was superior in terms of SoC for 5 compositions against
a result, the OO solutions exhibited inferior separation of
1 of the OO solution. For 3 compositions no difference was
concerns as they encompass classes with mixed concerns.
observed. In general, the interactions between the patterns in this
Moreover the shared classes in Java implementations presented
category are not addressed in the aspectization process. Their
low cohesion as their internal operations have a weaker coupling
implementations are basically disjoint, with no shared method or
between them. Figures 3 and 4 respectively illustrate the SoC and
class. The method calls that connect them typically were not part
cohesion superiorities of AO solutions through example pattern
of the functionality defined by the superimposed roles and usually
compositions in this category.
were not aspectized. As a result, the composition quality for this
category largely depended on the patterns being combined.
Considering the compositions analyzed, if at least one pattern
presents good results in its individual aspectization, the
consequence is an overall improvement of separation of concerns
in terms of the whole composition implementation. Similarly, the
OO solution is better when the composition contains patterns that
do not achieve satisfactory modularization in AO
implementations.
For example, the successful aspectization of the Interpreter pattern
has a positive influence on the general result of its composition (a) Separation of Concerns (b) other Measures
with the State pattern. As illustrated in Figure 2, this composition Figure 2. Results of an invocation-based composition:
presents better results in terms of the number of transition points Interpreter with State
(CDLOC) and also in the diffusion over components (CDC). This
With respect to separation of concerns, the pattern compositions
result is due to the effectiveness of AspectJ mechanisms to
can be further classified in 3 groups. The first group includes the
localize the Interpreter pattern. This AO solution transfers the
compositions where the two patterns were aspectized, and the
methods in charge of performing interpretations from the classes
AspectJ implementations of both of them have presented better
to the Interpreter aspect. As a consequence, the number of
separation of concerns. The combination involving Observer and
operations is not reduced (CDO) the diffusion over components
Prototype (Figure 3) is a representative of this situation: the roles
(CDC) is reduced from 14 to 1 and the number of transition points
of both patterns were better localized in terms of components
is reduced from 26 to 2 (Figure 2).
(CDC), operations (CDO), and transition points (CDLOC). In
The invocations among the patterns involved in the composition some measures, the superiority of AspectJ was higher than 20%
can be aspectized or not; it depends on the patterns involved in for both patterns involved in the composition.
the composition. There were only 3 cases where the inter-pattern
The second group of compositions also encompassed the
invocations were isolated in the aspects. We have observed that
aspectization of both patterns being composed. However, the
when the invocations are necessarily transferred to the aspect
AspectJ implementations have only shown SoC improvements for
code, the overall coupling of the composition tended to be worse.
one of the composed patterns, as is the case of the combination of
This problem has happened in the AspectJ implementation of the
Abstract Factory with Interpreter. Benefits were observed only in
combination of Interpreter with State (Figure 2). Similarly to the
the AO solution of the Interpreter (Figure 3). Finally, the
SoC measures, the other metrics, NOA and WOC, depended on
compositions in the third group involved the aspectization of only
each pattern involved in the composition due to the loose
one in each pair-wise composition. For example, the Observer
connection between the patterns.
pattern was the sole aspectized pattern in the composition with the

Observer Abstract Factory Observer Observer Abstract Factory Observer


Observer Abstract Factory Observer
25 with -4% with with with -0,6% with with
30
170 30 with with with
Prototype Interpreter Bridge Prototype Interpreter Bridge
Number of Transition Points

165 Prototype Interpreter Bridge


164 92%
Number of Components

Number of Operations

20 AO 25 25 AO
AO
OO OO
OO 90% 90%
20 20
15 93%
63% 63%
7%
15 0% 15 0%
0%
10
71% 71% 10 10 50%
0%
5 25% 20%
5 5

0 0 0
Observer Prototype Abstract Interpreter Observer Bridge Observer Prototype Abstract Interpreter Observer Bridge Observer Prototype Abstract Interpreter Observer Bridge
Factory Factory Factory

a) CDC measures (b) CDO measures (c) CDLOC measures


Figure 3. Separation of concerns in pattern compositions with class-level interlacing
Observer with Prototype AbstractFactory with Interpreter Observer with Bridge
40 42% 300 160 -13% 1800 45 250
49% -7%
AO AO -2% AO
35 -12% 140 1600 40
OO 250 OO OO
-19% 200
1400 35
30 120
200 1200 30
25 100
-4% 150
1% 1000 25
20 150 80
800 20
8% 100 8%
15 54% 8% 60 3%
100 2% 600 15 8%
10 40 33% 56%
400 10 50
50
5 20 200 5

0 0 0 0 0 0
CBC LCOO NOC NOA LOC WOC CBC NOC NOA LCOO LOC WOC CBC LCOO NOC NOA LOC WOC

Figure 4. Pattern compositions with class-level interlacing: coupling, cohesion, and size measures

Bridge pattern. The aspectized pattern was typically responsible and stronger coupling (CBC metric). However, these drawbacks
for improvements in the separation of pattern-specific concerns in will be discussed in Section 4.1.3 because similar findings were
the composition (Figure 3). However, the AspectJ superiority for obtained for these measures through all the composition
the Interpreter pattern has decisively contributed to the overall categories.
SoC of the composition. Specific constraints in the application
implementation or in the pattern combinations were the reasons 3.3 Method-level interlacing
for not aspectizing one of the patterns (see Section 4.1.4 for We have analyzed 17 compositions with method-level interlacing,
further details). which we have classified in 4 groups according to the similarities
in the measurement outcomes. The first group involved three
Interestingly, for all the 3 groups mentioned above, the AspectJ
combinations: Mediator with CoR, Observer with Composite, and
pattern implementations that present improved SoC are exactly
CoR with Strategy. The SoC measures for this group have shown
the ones that have exhibited superior results when analyzed in
no benefits in favor of AspectJ. These compositions involve an
isolation in the previous studies [9, 12]. It means that the
interesting scenario: the AspectJ implementation of one pattern
modularity of their AO solutions have scaled well in more
explicitly interferes in the separation of concerns relative to the
complicate pattern instances and in the presence of pattern
second pattern. The aspect of the first pattern inevitably contains
interactions with class-level interlacing. The AspectJ
code of the second one. It directly contributed to no SoC
implementations of specific patterns that did not show
improvements even in the combinations involving AspectJ pattern
improvements (e.g. Abstract Factory in Figure 3) also confirmed
implementations qualified as superior in previous studies [9,12],
results observed in our previous assessments [9].
such as Observer, CoR, and Composite.
Considering the other measures, the pattern combinations with
For example, the Java implementation of the method
class-level interlacing did not repeat the results in the previous
ConcreteMetaInvocationHandler.handleRequest() have code of
composition category. As discussed before, invocation-based
both Mediator and CoR patterns (Figure 1). The aspectization of
compositions (Section 3.1) have revealed much more influence of
the CoR pattern [12] implements this method as an inter-type
the two combined patterns in the overall results of the respective
declaration. As a result, the CoR aspect also contains code of the
compositions. The main reason is that they encompass loose
Mediator pattern, thereby leading to the increment of one in the
pattern interaction (i.e. simple method calls). Differing from those
CDC measure (Figure 5a). This means the Mediator code is
compositions, the outcomes here for all the 11 combinations with
inevitably scattered over an additional component in the AspectJ
class-level interlacing were very similar, independently from the
solution for this combination. Even if we try to refactor the
patterns taking part in the compositions. The presence of tight
method handleRequest, it still will contain a method call that is
coupling between the composed patterns (i.e. one or more classes
part of the Mediator behavior. As we will discuss in Section 4.1.4,
in common) led to similar benefits in the AspectJ implementations
the Mediator pattern has not been aspectized in this combination.
(Figure 4): (i) higher cohesion (LCOO metric), (ii) reduced
The size, coupling, and cohesion measures for this group have
number of attributes (NOA metric), and (iii) reduced number of
varied from composition to composition.
operations and parameters (WOC metric). These recurring
benefits are due to the reduction of tangling and scattering relative The second group includes only the composition Interpreter with
to the pattern-specific concerns in the classes shared by the Composite. To some extent, this combination presents a
composed patterns. The AspectJ implementations have also characteristic similar to the previous group: the Interpreter aspect
presented similar drawbacks in this category: more lines of code is forced to have two calls to the Composite aspect, which are
Mediator Mediator Decorator Interpreter Mediator Decorator Interpreter
Decorator Interpreter
with with with 50 with with with 39% 65
45 with with with 86%
12
CoR State Composite 73% CoR State Composite CoR State Composite 64
Number of Transition Points

45 40
Number of Components

Number of Operations

10 40 AO
89% 35 AO
AO OO OO
-13% 35
8 OO 30
30 0%
25
6 25 90%
20 56%
20
75% 0%
4 15
0% 15 0% 0%
82% -9%
10 - 11% 10 25% 75%
2
5 5

0 0 0
Mediator CoR Decorator State Interpreter Composite Mediator CoR Decorator State Interpreter Composite Mediator CoR Decorator State Interpreter Composite

(a) CDC measures (b) CDO measures (c) CDLOC measures


Figure 5. Separation of concerns in pattern compositions with method-level interlacing
Mediator with CoR Decorator with State Interpreter with Composite
40 250 -16% 40 160 90 900 6%
0% -6%
AO AO -1%
35 35 9% 140 80 800
OO OO
200 AO
30 70 700
30 120 OO
63%
60 600
25 -48% 25 100
150
50 500
20 61% 20 -17% 80
28% 40 400
9% 18%
15
100 -11% 15 60
0%
30 300
45%
10 10 38% 40
50 71% 20 200
5 5 20 10 100

0 0 0 0 0 0
CBC LCOO NOC NOA LOC WOC CBC LCOO NOC NOA LOC WOC CBC NOC NOA LCOO LOC WOC

Figure 6. Pattern compositions with method-level interlacing: coupling, cohesion, and size measures
implemented using aspectOf. Nevertheless, the overall separation an order in their executions needs to be established using declare
of concerns of the AO solution for this combination is superior precedence. This feature introduces additional coupling in the AO
(Figure 5). The Java implementation of Interpreter classes was solution (Figure 6). Although with distinct implementation
highly tangled with Composite code, which is effectively strategies, similar results are obtained for the other 8 pattern
modularized in the AspectJ implementation. In addition those two compositions in this group.
calls located at the Composite aspect are in two different classes The last group in this category encompasses 3 different
of the Java solution, contributing to the AspectJ victory. As compositions involving the Bridge pattern, and the combination
Figure 6 shows, this composition has revealed a high cohesion of Factory Method with Memento. In these combinations, one of
(LCOO), fewer attributes (NOA), and fewer operations and the patterns has not been modularized as aspects in the AspectJ
parameters (WOC). implementation. The aspect of the second pattern modularizes its
The third group is formed by 9 combinations: Decorator with code that was tangled in the “interlaced” method. In this way, the
Prototype, Decorator with State, Mediator with Prototype, separation of concerns and cohesion for the compositions in this
Mediator with State, Prototype with Strategy, State with Strategy, group were notoriously improved.
Prototype with Template Method, and State with Template
Method. In these cases, the AspectJ implementation of one pattern 3.4 Overlapping
does not interfere in the separation of concerns relative to the We have analyzed 25 compositions with overlapping, which we
second pattern. An explicit separation of concerns was achieved have classified in 4 groups according to the similarities of the
between the two patterns because each aspect isolates all the overlapping nature: attribute overlapping, statement overlapping,
crosscutting code relative to the corresponding pattern. Their partial class overlapping and total or complete overlapping. We
aspectization also separates the code of the two patterns that is have not found any pattern combination involving method
mixed in the methods they have in common in the Java overlapping in the 62 compositions analyzed.
implementation. Attribute overlapping occurs when two or more patterns share a
For instance, the
implementation of the methodJava same attribute. In the 3 investigated compositions with attribute
ConcreteBind. makeRequest() includes pieces of code from both overlapping, the shared attribute was transferred to one of the
Decorator and State patterns (Figure 1). The AO solution of this aspects and accessed by the other pattern aspect through the
combination modularizes those pieces of code in the advices of invocation of aspectOf. As a consequence, the separation of
the aspects implementing each pattern. Both aspects define the pattern roles is increased, but the coupling is stronger. For
execution of the method makeRequest() as join point of interest. instance, in the composition of Composite and Visitor patterns, an
This method is not aspectized because it is part of the Mediator attribute is responsible for maintaining the reference to the
pattern, which has not been refactored as an aspect in the composite object, and it also plays the ObjectStructure role of the
middleware case study (Section 4.1.4). In fact, we can see in Visitor pattern. It means that a same attribute is used in a
Figure 6 that the AspectJ solution presents improved locality of different way for each pattern. In the aspectization process, the
pattern-specific concerns for this combination. However, since attribute is maintained in the Visitor pattern and is removed of the
both aspects in this combination are affecting the same join point, Composite and replaced by an invocation to aspectOf. In spite of

Composite Composite Decorator Prototype


Decorator Prototype Composite Decorator Prototype
with with with with
with with 25 with with with
9
Visitor Visitor Bridge State 25 Visitor
Bridge State Bridge State
Number of Transition Points

8 AO
Number of Components

AO
Number of Operations

AO 20 OO
7 OO OO 20
76% 56%
33%
6
20% 15 86%
15 86%
5
82% 25% -9% 67%
50% 75% 50% 0%
4 0% -20%
10 10
3
75%
60%
2 5 5
1

0 0 0
Composite Visitor Decorator Bridge Prototype State Composite Visitor Decorator Bridge Prototype State Composite Visitor Decorator Bridge Prototype State

(a) CDC measures (b) CDO measures (c) CDLOC measures


Figure 7. Separation of concerns in pattern compositions with overlapping
Composite with Visitor Decorator with Bridge Prototype with State
180 25 140
14 120 45 -29%
-23% 7% 10%
AO -16% 40
AO 160 -48% 120
12 OO 100 OO
20
35 140 AO
100
10 OO
80 30 120
15
8 25 100
80

60
20 26%
6 30% 12% 80
10 60
-16%
40 15 18% 60
4 0% -16%
100% 33% 40
10 57% 40 5 25%
0%
2 20
5 20
20

0 0
0 0
0 0
CBC LCOO NOC NOA LOC WOC CBC LCOO NOC NOA LOC WOC CBC NOC NOA LCOO LOC WOC

Figure 8. Pattern compositions with overlapping: coupling, cohesion, and size measures

the stronger coupling, this strategy led to a stronger cohesion pattern are transferred to the Decorator aspect and “removed”
(LCOO) and the reduction of operations and parameters (WOC) from the application. In general, the aspectization process of
in the AO implementation. These positive results are illustrated in compositions with partial class overlapping, the aspectization of a
Figure 8. In the other 2 compositions with attribute overlapping, pattern implies that the second pattern is not aspectized. Similarly
the results were not similar because there were so many inter- to the other 14 combinations, the aspectization of the Decorator
aspect invocations due to the shared attribute. This problem led to pattern combined with the Bridge pattern resulted in improved
a reduction of separations of concerns (in terms of the three SoC and also a slightly reduction of coupling, LOC and WOC.
measures) and an augment on the coupling between components.
In Figure 7, which depicts the composition of Composite and 4. DISCUSSIONS
Visitor, the influence of attribute overlapping is lower because
there is only one invocation of aspectOf. 4.1 General Analysis
This section introduces a more qualitative analysis by discussing
We have analyzed 4 compositions with statement overlapping, in the four questions raised in the introduction and using the
which the involved patterns share, at least, one statement. In the collected quantitative data (Section 3) as the basis. When
combination of Prototype and State a given statement creates a appropriate, we also correlate through the sections below the
clone and also modifies the state of a variable that represents the findings in our evaluation with claims and results from previous
current state. We have observed for the 4 compositions that, in systematic case studies [9, 12] (Section 2.1).
general, the aspectization leads to the augment of separation of
concerns and tends to increase the coupling between the patterns. 4.1.1 Does AOP enhance pattern composability?
This stronger coupling is because aspect code is intermingled with For the context of this study, we consider that a pattern
the invocations to the other pattern aspect. Thus, similarly to the implementation has a “good” composability if it can be directly
attribute overlapping, the coupling between components is reused and smoothly extended to different composition contexts.
increased after aspectization due to the inter-aspect coupling in A transparent pattern composition would require only
addition to: (i) the natural coupling between the business classes, concretizing abstract aspects and extending abstract pointcuts and
and (ii) the coupling between the classes and the aspects. Figure methods. The core implementation of the pattern roles should not
8 shows the augment of coupling, cohesion and WOC in the be aware of the composition specificities. Moreover the
combination of Prototype with State. aspectization of the pattern composition should not impact
In the three other compositions occurs a class overlapping. This negatively on the modularity attributes. The results reported in
overlapping occurs when at least one class is shared by patterns Section 3 suggest that the success or failure for supporting a
involved in a composition. This overlapping can be total or straightforward composition aspectization depended basically on
partial. The total class overlapping is when a pattern is completely two key complementary factors: (i) the suitability of AOP to
contained in another pattern. The composition of the Template modularize a given design pattern, and (ii) the intricacies of the
Method and the Decorator patterns is an example of total pattern composition instance at hand. The predominance of a
overlapping (Figure 1) where the Decorator and factor over the other depended on the composition category.
ConcreteDecorator roles of the Decorator pattern contain the The first factor predominated when we had two patterns taking
AbstractClass and ConcreteClass roles of the Template Method. part in an invocation-based composition (Section 3.1) or simply
The aspectization process of the dominant pattern (Decorator) having one or more classes in common (Section 3.2). There is a
removed the subordinated pattern (Template method). This feature loose connection between the involved patterns in these cases. As
impacts on the SoC metrics (Figure 7) with the reduction of SoC a result, the composition transparency and the achieved
and also the number of transition points. Coupling, LOC and modularity degree depended mostly on the adequacy of AspectJ
WOC are also reduced (Figure 8). mechanisms to isolate the crosscutting concerns relative to each
With respect to the partial class overlapping, 15 compositions separate pattern. The particularities of compositions based on
were found in our case studies. In these combinations, part of the invocations and class-level interlacing did not impose major
involved patterns share one or more classes. For instance, the problems. For most of the investigated compositions, we were
composition of Decorator with Bridge shared two classes that able to use the reusable pattern implementations as proposed in
played two Bridge roles (Implementor and Concrete Implementor) [12] without changes to the core structure of the patterns. We
and two Decorator roles (Decorator and ConcreteDecorator). The have used in few cases a different implementation, but because in
original classes of the Bridge pattern shared by the Decorator such situations the application circumstances required pattern
variants. In fact, most measures for the patterns participating in composition-oriented evaluation. The last two columns are
such compositions in this study were similar to the measures we respectively concerned with the number of compositions each
have obtained for each individual pattern in our previous pattern participates and if the used version follows the original
quantitative study [9]. implementation proposed by Hannemann and Kiczales [12]. In
However, an important finding of this study is that the presence of second column’s cells, the value “yes” means that the
more intricate relationships between two patterns can hinder a corresponding AspectJ pattern implementation was qualified with
smooth composition process and, sometimes, affect negatively the a good localization in terms of its roles. With respect to the
modularity attributes of the patterns being composed. As reported second and third columns, we have classified an AspectJ (labeled
in Sections 3.3 and 3.4, some pattern compositions with intra- "AO") or Java (labeled "OO") solution as superior when it has
method interlacing and overlapping required additional achieved better results for separation of concerns. In the third
restructuring steps in the original pattern implementations as column, the conclusion was based on the analysis of how many
proposed in [12]. For example, sometimes we need to change the compositions a given OO or AO solution were better when
original structure of the pattern and use inter-type declarations in compared with the results of the other solution. The AspectJ
one pattern aspect so that the second pattern aspect can be solutions that achieved the best results (more than 35% in all SoC
properly combined with the former. This means that the aspectual measures) for all compositions are marked with the symbol “+” in
design of the pattern needed to be aware of the composition the third column. Finally, the symbol “*” in the last column means
context and the generic pattern aspect could not be directly that the pattern was not aspectized in this study (Section 4.1.4),
reused. what also means a negative result for the AO solution.

This scenario happened in the AspectJ implementation of State Table 2. Overview of the main findings of the three studies
with Observer for the middleware case study. The Observer aspect Previous Studies This Study
was interested in events related to invocations of methods of the

Implementations
State aspect. These steps were often required even for patterns

Our First Study

Compositions
which have been qualified as reusable and/or pluggable [12] in

Separation of
the previous case studies, such as State, Adapter, and Strategy. Pattern

Number of
HK Study
(Locality)

Concerns
Such refactoring steps do not necessarily led to negative effects on

Original
(SoC)
the modularity attributes of the pattern composition. Indeed a
number of cases indicated that the AspectJ solutions were
superior, such as the composition of State with Observer
mentioned above. Abstract Factory No OO = 2 yes
Adapter Yes AO = 2 yes
However, as discussed through Section 3, the aspectization of Bridge No OO = 7 no*
some specific compositions with strong coupling between the Builder No OO = 2 yes
patterns can bring modularity problems. For example, there were CoR Yes AO = 6 yes
compositions where a pattern aspect inevitably contained code of Command Yes AO = 4 yes
the second one, thereby affecting negatively the overall separation Composite Yes AO AO+ 6 yes
of concerns (Section 3.3). Moreover the aspectization of different Decorator Yes AO AO+ 7 yes
types of overlapping-based compositions tended to present SoC Façade Same Implementation for 2 yes
improvements, but also typically resulted in additional couplings Java and AspectJ
between the modules participating in the composition (Section Factory Method No OO OO 8 yes
3.4). Interestingly, some cases involved design patterns that have Flyweight Yes OO = 4 yes
shown superiority for AspectJ implementations in previous Interpreter No = AO 4 no
studies [9, 12], such as CoR and Adapter. Section 4.1.4 shows Iterator Yes AO AO 4 yes
Mediator Yes AO = 7 no*
that some additional issues can emerge in compositions involving
Memento Yes AO AO 3 yes
more than two patterns.
Observer Yes AO AO+ 11 yes
4.1.2 Separation of roles in pattern compositions Prototype Yes AO AO 7 yes
Proxy Yes AO AO 8 yes
Section 3 has focused the discussion of the results for separation
Singleton Yes AO AO 4 yes
of concerns under the composition point of view. This section
State Yes = AO 8 yes
summarizes and discusses the results for separation of concerns in Strategy Yes AO AO 7 no
terms of each design pattern. Previous evaluations [9, 12] have
Template Method Yes OO AO 7 no*
centered the assessment on individual instances of design patterns. Visitor Yes AO AO 4 yes
In this study, our goal is to understand to what extent separation (+) indicates the AO solutions that achieved the best results in all
of each pattern roles is preserved in contexts involving pattern compositions
compositions. (*) indicates the patterns which weres not aspectized in this study
Table 2 summarizes the findings on separation of concerns (SoC) Table 2 shows that only one design pattern has clearly presented
for each GoF design pattern. The rows of the table present all 23 superior separation of pattern-related concerns in Java
design patterns, while the columns show the main SoC implementations. Factory Method pattern provided better results
conclusions of the other experiments and this study. The second in separation of concerns for OO version and this finding
and third columns respectively describe the SoC results (locality) confirms our first study result (column 2). In addition, the AspectJ
of the HK study [12] and of our first study [9]. The fourth column implementations of 13 patterns in this study have shown better
summarizes the SoC findings related to each pattern in our
results in terms of separation of concerns, and 9 patterns presented modularity improvements, confirming the findings of previous
similar (or not conclusive) results in both OO and AO case studies (columns 2 and 3 of Table 2).
implementations. For the 13 patterns that have shown SoC
superiority in AspectJ implementations, only two (Interpreter and 4.1.3 Coupling, cohesion, and size
State) refuted findings of our previous study, when they were Based on the results presented in Section 3, we have observed that
analyzed in isolation. In the previous study, they were classified the measures relative to cohesion (LCOO), complexity of
as “similar results in both OO and AO implementations”. operations (WOC), and number of attributes (NOA) were also
However, the Interpreter solution used in this study was different correlated with the composition category and the involved
from original HK implementation, which was also used in our patterns. In general, the AO solutions were superior in terms of
previous evaluation. Due to different application constraints, all NOC measures, since the use of AspectJ reduces the overuse of
interpret() methods were moved to the aspect and introduced to inheritance mechanisms. However, as illustrated in Figures 4, 6,
classes by inter-type mechanisms (Section 3.1). and 8, most measures indicated that AspectJ implementations
resulted in higher coupling (CBC) and more lines of code (LOC)
The State pattern had its modularity improved in most of AO than the respective Java implementations.
compositions (6 against 2). In the two cases where no SoC
improvement was detected, the AspectJ implementations were However, a careful analysis of the implementations show that
exactly the same as proposed by the HK study. In the HK these higher CBC and LOC values for AO solutions in several
implementations, the state transitions are located in Java classes cases were related to presence of generic aspects in several
that play the State role, which is usually defining (Section 2.1). AspectJ pattern implementations. These aspects have the purpose
For example, this result was observed in the combination of State of making the pattern solutions more reusable. As several
with Interpreter (Section 3.1). Differently from the original HK investigated compositions involved a few participant classes
implementation, the state transitions in the other 6 playing the pattern roles, the presence of generic aspects
implementations occur in the classes that play the Context role in artificially has lead to higher values for LOC and CBC. This effect
the State pattern [6]. This role is typically superimposed, and the was more evident when we compared the composition instances
state transitions in those classes result in high tangling and taken from the middleware implementation with the composition
scattering of the pattern implementation. In these cases, the instances obtained from the agent-based application and the
aspectization process is also effective to remove the state measurement tool. Due to the different application features, the
transitions from the business classes and other pattern former ones often involved few participant classes while the other
implementations, reducing the tangling and scattering. The ones typically consisted of several participant classes. For
AspectJ superiority for these State instances can be observed in example, the composition Decorator with Bridge (Figure 8) was
combinations appearing in Figures 5 and 7, where the difference taken from the measurement tool and has exhibited favorable
is higher than 56 % for the CDLOC measures. The Java LOC and CBC values for the AspectJ implementation.
implementation is superior in the CDO measures, but it is because Nevertheless, it is important to highlight that in several cases a
the State aspects have an additional operation. In addition, the higher CBC value was in fact a clear indicator of stronger
difference is lower than 10 %, which can be considered as coupling in the AspectJ solution, as discussed through Section 3
insignificant. and Section 4.1.1. For example, coupling problems happened in
The 9 patterns with similar results for AO and OO versions some invocation-based compositions when the inter-pattern
(represented by “=” in column 4) can be classified in two main invocations were inevitably transferred to the code of the aspects
situations. The first situation includes three patterns - Bridge, (Section 3.1). As there was an implicit connection between the
Mediator and Template Method, which were not aspectized base classes, the aspect-class and inter-aspect dependencies
because application constraints or composition particularities introduced new sources of coupling in the composition
(Section 4.1.4). In the second case, the pattern aspectization has implementation. Other coupling-related problems were identified
not produced SoC improvements in almost all the compositions in compositions with intra-method interlacing (Section 3.3) and
those patterns participated. This category included: Abstract overlapping (Section 3.4).
Factory, Adapter, Builder, CoR, Command, and Flyweight. We
have identified 3 main factors that determine the negative
4.1.4 Scalability of AOP in complex compositions
performance of AspectJ for modularizing those patterns: (i) the The previous sections focused on discussing how the
composition particularities that the pattern participated, (ii) the aspectization of pair-wise compositions impacts different
pattern instance size, i.e. the number of classes playing the pattern modularity attributes. This section discusses how AOP scaled in
roles, and (iii) the aspectization approach. The CoR pattern, for compositions involving a greater number of patterns in terms of
instance, is an example in which the performance was influenced such modularity attributes and pattern composability. We have
by the compositions it took part. The method-level interlacing implemented and analyzed different compositions with 3, 4, 5, 6,
composition “CoR with Strategy” have shown no benefits in favor and 7 patterns, such as the one represented in Figure 1. In general,
of AspectJ because the aspectization of Strategy brings code of we have observed that the measures tended to be similar in these
the CoR pattern to its aspect (Section 3.3). The Command pattern more complex compositions, especially when they mostly
has also not exihibited an improved separtion of concerns in the involved invocation-based and intra-class compositions. However,
AspectJ implementations. In this case, the main factor was the we have detected some problems when the combination included
instance size. There were not too many classes in the application a high incidence of intra-method interlacings and overlappings.
playing the roles Command, Receiver and Invoker. The Abstract In some situations, these problems hindered the aspectization of
Factory, Builder and Flyweight patterns have presented no certain design patterns, such as Proxy and Mediator. The
aspectization of certain patterns, as proposed in [12], can cause
some design conflicts, which can be considered as a positive patterns. Other researchers can reuse our study format as a basis
result in favor of Java implementation. As a consequence, it is for further studies intended to investigate other design patterns.
necessary to carefully analyze which patterns should be aspectized There are a number of other existing metrics and other modularity
and which patterns should not. Consider for example the dimensions that we could exploited in our study. We have to
composition of Proxy, Flyweight, and Adapter patterns. The decide to focus on the metrics described in Section 2.3.2 because
Adapter, FlyweightFactory, and RealSubject roles have a class in they have already been proved to be useful in several previous
common. The HK implementation of the Flyweight pattern case studies as effective quality indicators in several case studies,
suggests the transformation of FlyweightFactory into an aspect. including [4, 7, 8, 9, 20]. In fact, despite the well-known
On the other hand, the Adapter implementation requires the limitations of these metrics, as already discussed in [9], they
removal of the Adapter class, and the use of inter-type complement each other and are very useful when analyzed
declarations to insert its methods in the class is playing the together. In addition, there is no way in a single study to explore
Adaptee role. The Proxy pattern acts as a client in this all the possible measures. For every possible metrics suite that
composition. With the divergence of these two suggestions, it is someone takes, there will be always some dimensions that will
necessary to choose which pattern should be aspectized and if the remain uncovered. In addition, future case studies can use
Proxy pattern will invoke the aspect represented by additional metrics and assess the pattern compositions in terms of
FlyweightFactory or will invoke a method defined in the Adaptee. different modularity dimensions.
In the implementation of the middleware system we have chosen
to aspectize the Adapter pattern because this approach would It is also important to notice that the scope of our experience is
reduce the coupling among the elements of the composition. The limited to: (i) the patterns selected for this comparative study, (ii)
decision of aspectizing the Adapter pattern made the aspectization the specific Java and AspectJ implementations mostly based on
of Flyweight impossible. This also reveals that the results of the the GoF book [6] and the HK study [12], (iii) the Java and
aspectization of Proxy with Flyweight and Proxy with Adapter are AspectJ programming languages, (iv) the composition categories
different from the aspectization of the combination of such three described in Section 2.2, and (v) our 3 case studies. Although our
patterns: Proxy, Flyweight and Adapter. As a result, in evolution study covers a huge number of pattern compositions and different
scenarios, these pair-wise combinations may need to be composition categories, it obviously does not cover all the
restructured in the need of adding a third pattern. composition possibilities. For instance, it does not exploit method
overlapping. However, we believe that this first empirical study
In some cases, the aspectization of a given design pattern in on the aspectization of pattern compositions provided interesting
complex compositions has not been revealed as a good design evidences about benefits and drawbacks on the use of AO
option according to application requirements. Consider the abstractions might bring, as discussed in Sections 3 and 4.1.
example illustrated in Figure 1 involving the Mediator pattern as a
central design element. In this case, the Mediator and Proxy 5. RELATED WORK
patterns are combined to implement the LocalBind mechanism of Related work can be categorized into two groups: those related to
OpenOrb. The Proxy pattern is used to maintain the contracts pattern composability and those that empirically investigate
defined between the components. In this example the BankStub aspectization of multiple crosscutting concerns.
class is used as a Proxy to access the implementations defined by
the Bank Subject. The Mediator pattern supports the dynamic 5.1 Pattern Composability
adaptation mechanism of OpenOrb. In this case, the BankStub There are several ways of classifying relationships between design
class also plays the Colleague role by inheriting the bind attribute patterns according to different purposes [21, 23]. Zimmer [23] has
from the Interface and Port classes. This attribute supports the proposed a classification of the relationships between the GoF
invocation of bindlocal() of the ConcreteBind class. The design patterns. The following categories were proposed: (i) X
aspectization of these two patterns would require the definition of uses Y, (ii) X is similar to Y, (ex.: Abstract Factory, Prototype
an advice to handle each method provided by the client’s and Builder deal with object creation; Glue and Mediator
interfaces. In addition, all invocations would be forwarded to the decouple objects); and (iii) X can be combined with Y (a Factory
abstract Mediator aspect. As a result, the Mediator pattern has not Method is typically called in a Template Method; Composite and
been aspectized because this strategy would insert a bottleneck in Decorator are often used together). However, this is a higher-level
the invocation of the middleware platform and, as a consequence, classification used with the purpose of improving the
the performance would be reduced. documentation of pattern languages. The classification used in
this work was focused on the composition of the implementations
4.2 Study Constraints for pattern solutions; indeed, it was abstracted from pattern
The use of the GoF patterns could be pointed out as a constraint in realizations in several real system implementations [2,4,8] and our
our experimental evaluation. However, we have focused first on own experience on pattern compositions.
this pattern catalogue for two main reasons. First, the GoF Murali et al [16] discusses the use of design patterns and AOP in
patterns are domain-independent and widely-used solutions. a middleware implementation. They claim that the combination
Second, this adopted strategy allowed us to compare our results of AOP and design patterns lead to many benefits to the
with previous case studies that exploited these patterns, and middleware in terms of reusabilility, modularity, and adaptability.
understand how the pattern implementations scaled in the Rouvellou et al. [17] have discussed how middleware modularity
presence of pattern interactions. As previous work has not can be improved by using separation of concerns strategies. They
systematically investigated the influence of AOP on pattern have theoretically stated that the entanglement between
composability, we believe this study improves the current middleware components is low when they are highly separable.
knowledge base about the aspectization of these general-purpose However, these authors do not apply any metrics to assess the
implementation and do not give an empirical support for such [4] Filho, F., Rubira, C., Garcia, A. A Quantitative Study on the
conclusions. In addition, they do not analyze the composition of Aspectization of Exception Handling. Proc. ECOOP
patterns used in the implementation. Workshop on Exception Handling in OO Systems, Glasgow,
Scotland, July 2005.
5.2 Other Empirical Studies [5] Florijn, G., Meijers, M., Winsen, P. van. Tool support for
There are a number of quantitative studies (such as [4,8, 9, 11]) object-oriented patterns. Proceedings of ECOOP 1997.
that apply the same metrics used in this work. However, none of [6] Gamma, E. et al. Design Patterns: Elements of Reusable
them applies the metrics upon pattern compositions. Godil and Object-Oriented Software. Addison-Wesley, 1995.
Jacobsen [11] have applied the metrics to evaluate an aspect- [7] Garcia, A. From Objects to Agents: An Aspect-Oriented
oriented version of a database system refactored using the Approach. Doctoral Thesis, PUC-Rio, Brazil, April 2004.
horizontal decomposition principle. Although they applied the [8] Garcia, A. et al. Separation of Concerns in Multi-Agent
metrics to assess an AO implementation, they do not use design Systems: An Empirical Study. In Software Engineering for
patterns in such a system. Multi-Agent Systems II, Springer, LNCS 2940, Jan 2004.
Soares at al [20] has focused on the investigation of AOP to [9] Garcia, A. et al. Modularizing Patterns with Aspects: A
modularize distribution and persistence concerns. They have used Quantitative Study. Proc. of the 4th Intl. Conference on
specific design patterns to implement Java and AspectJ versions Aspect-Oriented Software Development, 2005, 3 - 14
of a web-based system. The authors have concluded that the [10] Garcia, A. et al. Engineering Multi-Agent Systems with
AspectJ implementation is better than the corresponding Java Aspects and Patterns. J. of the Brazilian Computer Society,
implementation. However, this study has also not assessed the 1, 8 (July 2002), 57-72.
suitability of AOP to isolate pattern implementations in the [11] Godil, I., Jacobsen, H. Horizontal Decomposition of
presence of intricate pattern interactions. Prevayler. In Proc. of CASCON 2005, Richmond Hill,
Canada, October 2005.
6. CONCLUSION [12] Hannemann,J., Kiczales,G. Design Pattern Implementation in
Since the publication of the first catalog containing the 23 Gang-
Java and AspectJ. Proc. OOPSLA’02, Nov 2002.
of-Four patterns [6], design patterns have quickly been recognized
[13] Java Reference Documentation.
to be useful and important in successful software development. It
http://java.sun.com/reference/docs/index.html.
is well recognized that programming languages affect pattern
[14] Kiczales, G. et al. Aspect-Oriented Programming. Proc. of
implementation. Hence it is natural to explore the effect of AOP
ECOOP’97, LNCS 1241, Finland, June 1997, 220-242.
techniques on the implementation of the GoF patterns. This paper
[15] Lopes, C. D: A Language Framework for Distributed
presented an empirical study that investigated the scalability of
Programming. PhD Thesis, Northeastern University, 1997.
AOP for composing GoF design patterns. We have used 3
[16] Murali, T., Pawlak, R., Younessi, H. Applying Aspect
medium-sized systems implemented in Java and AspectJ, and
Orientation to J2EE Business Tier Patterns. Aspects,
evaluated 62 compositions in these systems.
Components and Patterns for Infrastructure Software
We also compared our results with the findings from previous Workshop, AOSD2004, pp 55-61, 2004, Lancaster, UK
studies, contributing to an improved body of knowledge on the [17] Rouvellou, I., Sutton, S. and Tai, Stefan. Multidimensional
scalability of AOP. We defined a categorization of pattern Separation of Concerns in Middleware. Workshop on
compositions, and the relationships with different ways of MDSoC in Sof. Engineering (ICSE 2000), Ireland, 2000.
crosscutting. For each category, we analyzed the compositions, [18] Sant’Anna, C. et al. On the Reuse and Maintenance of
determined the aspectization approach, applied the metrics, and Aspect-Oriented Software: An Assessment Framework. Proc.
presented in this paper a depth analysis of the results. The study of Brazilian Symposium on Software Engineering (SBES’03),
shows that the aspectization results depend on the patterns Manaus, Brazil, Oct 2003, 19-34.
involved, the composition intricacies, and the application [19] Sant’Anna, C. et al. Design Patterns as Aspects: A
requirements. In some situations, the aspectization of the pattern Quantitative Assessment. Proc. of Brazilian Symp. on
composition is not straightforward and several design options Software Engineering (SBES’04), Brazil, Oct 2004.
need to be considered. Sometimes, it requires a global reasoning [20] Soares, S. An Aspect-Oriented Implementation Method.
in order to understand the impact of each design option in the Doctoral Thesis, Federal Univ. of Pernambuco, Oct 2004.
context of the whole system implementation. In order to extend [21] Soukup, J. Implementing Patterns. In: Coplien J. O.,
the body of knowledge on the aspectization of design patterns, as Schmidt, D. C. (eds.) Pattern Languages of Program Design.
a future work we intend to use other AO programming languages, Addison-Wesley 1995, pp. 395-412.
such as Caesar and Hyper/J, and apply the same metrics used in [22] Zhao, J. and Xu, B. Measuring Aspect Cohesion. Proc. Proc.
this work. FASE'04, LNCS 2984, March 2004, 54-68.
[23] Zimmer, W. Relationships between Design Patterns. Pattern
7. REFERENCES languages of program design, pp. 345 – 364, 1995
[1] AspectJ. The AspectJ Guide. http://eclipse.org/aspectj/. [24] Yacoub, S. and Ammar, H. Composition of Design Patterns.
[2] Blair, G. et al. The design and implementation of Open Addison Wesley, 2003.
ORB. IEEE Distributed Systems Journal, 2(6), 2001. [25] Composing Design Patterns with AOP.
[3] Figueiredo, E. et al. Assessing Aspect-Oriented Artifacts: www.consiste.dimap.ufrn.br/~cacho/composition.html
Towards a Tool-Supported Quantitative Method. Proc. of the
9th ECOOP Workshop on Quantitative Approaches in OO
Soft. Engineering (QAOOSE.05), Glasgow, July 2005.

You might also like