Title: Modularizing Design Patterns with Aspects: A Quantitative Study
1Modularizing Design Patterns with AspectsA
Quantitative Study
- Alessandro Garcia1 Cláudio SantAnna2
Eduardo Figueiredo2 - Uirá Kulesza2 Carlos Lucena2 Arndt von
Staa2 - Lancaster University, UK
- PUC-Rio, Brazil
8 August 2005
2Motivation
- Design patterns are recognized as useful and
important - 23 Gang-of-Four (GoF) patterns
- patterns assign roles to their participants
- roles define the functionality of the
participants in the pattern - A number of patterns exhibit crosscutting
concerns - Pattern roles vs. participant classes
- Recent studies (e.g. HK02)
- OO abstractions are not able to modularize those
concerns
HK02 Hannemann, J., Kiczales, G. Design
Pattern Implementation in Java and AspectJ,
Proceedings of OOPSLA02, November 2002 , pp.
161-173.
?
3Motivation An Example
- The Observer Pattern
- role subject
- holds reference to observers
- notifies them about changes
FigureElement
Figure
ltltinterfacegtgt Subject
addObserver removeObserver notify
1
observers getX getY getColor addObserver removeObs
erver notify setX setY setColor
Point
Line
update Display
Screen
observers getP1 getP2 getColor addObserver removeO
bserver notify setP1 setP2 setColor
Members exclusively dedicated to the pattern
Methods including some code relative to the
pattern
4The Problem
- There is a need for investigating the suitability
of AOP for improving the modularization of design
patterns - qualitative and quantitative studies OO vs. AO
- replication
- Towards empirical evidence
- impact of the aspectization of design patterns
on well-established attributes - separation of concerns
- coupling, cohesion, and size
- improved reusability
- scalability of aspect-oriented solutions for
design patterns
5Limitations of Related Work
- Hannemann and Kiczales (HK) have developed the
only systematic study - Explicitly investigated the use of AspectJ in the
implementation of the GoF patterns - However
- A qualitative investigation
- Focus on separation of concerns
- Attributes not very well defined in empirical
software engineering - E.g. composability and (un)pluggability
- Scalability not explored
HK02 Hannemann, J., Kiczales, G. Design
Pattern Implementation in Java and AspectJ,
Proceedings of OOPSLA02, November 2002 , pp.
161-173.
?
6Our Quantitative Study
- Complementation of the HK study
- replication of the study, supplementing it with
empirical data - improvement of our knowledge about the
aspectization of design patterns - Quantitative assessments based on metrics for
- Separation of Concerns (SoC)
- Coupling
- Cohesion
- Size
7Outline
- The Problem
- Hannemann Kiczales Study
- Our Study Setting
- Metrics
- Assessment Procedures
- Results
- Separation of Concerns
- Coupling, Cohesion and Size
- Discussions
- General Analysis
- Study Constraints
- Conclusion
8Hannemann Kiczales Study
- Goals
- develop and compare Java and AspectJ
implementations of the 23 GoF design patterns - improve the modularization of the pattern roles
9Hannemann Kiczales Study
- Goals
- develop and compare Java and AspectJ
implementations of the 23 GoF design patterns - improve the modularization of the pattern roles
- Example
Reusable Aspect
- Some results
- SoC improvements in 17 patterns
- superior reusability achieved in 12 patterns
10Outline
- The Problem
- Hannemann Kiczales Study
- Our Study Setting
- Metrics
- Assessment Procedures
- Results
- Separation of Concerns
- Coupling, Cohesion and Size
- Discussions
- General Analysis
- Study Constraints
- Conclusion
11Our Study Setting
- Goal compare AspectJ and Java implementations of
the GoF patterns in a quantitative manner - Assessment of the HK implementations
- Organized in 4 phases
- Alignments
- addition of functionalities
- removal of functionalities
- similar coding styles
- alignments of tracing statements
- ...
12Phase 2 Evolution
- Inclusion of new participants in the pattern
implementations - Application of the metrics
- original implementation vs. evolved
implementation - verify the scalability of the solutions
13Phase 2 Evolution
- Inclusion of new participants in the pattern
implementations - Application of the metrics
- original implementation vs. evolved
implementation - verify the scalability of the solutions
FigureElement
Figure
1
getX getY getColor addObserver removeObserver noti
fy setX setY setColor
Point
update Display
Screen
14Phase 2 Evolution
15Measurement
Metrics
Concern Difusion over Components
Attributes
CDC
Phase 3
Concern Difusion over Operations
CDO
Separation of Concerns
Concern Difusion over LOC
CDLOC
Lines of Code
LOC
Size
Number of Attributes
NOA
Coupling
Weighted Operations per Component
WOC
Phase 4
Cohesion
Coupling between Componentes
CBC
Depth of Inheritance
DIT
Lack of Cohesion in Operations
LCOO
C. SantAnna, A. Garcia, C. Chavez, C. Lucena, A.
Staa. On the Reuse and Maintenance of
Aspect-Oriented Software An Assessment
Framework . Proc. of the ACM Sigsoft XVII
Brazilian Symposium on Software Engineering,
Manaus, Brazil, October 2003, pp. 19-34.
?
16Metrics - Separation of Concerns
- Viewpoint Concern
- Concerns investigated roles of each design
pattern
Role subject CDC - Components 3 CDO -
Operations 13 CDLOC - Transition Points 10
17Metrics - Coupling
- Viewpoint Component
- It extends the CBO metric CK94
- Measures the number of components which are
coupled to a given component - ? coupling -gt easier to maintain and reuse
AO
OO
ltltcrosscutsgtgt
CBC (Coupling between Components)
CK94 Chidamber, S., Kemerer, C. A Metrics
Suite for Object Oriented Design. IEEE
Transactions on Software Engineering, 20 (6),
June 1994, pp. 476-493.
?
18Outline
- The Problem
- Hannemann Kiczales Study
- Our Study Setting
- Metrics
- Assessment Procedures
- Results
- Separation of Concerns
- Coupling, Cohesion and Size
- Discussions
- General Analysis
- Study Constraints
- Conclusion
19Results
- Graphics illustrate the measurement results
system viewpoint
CDC
20Results
- Separation of Concerns (SoC)
- Increased Separation
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Decreased Separation
- Template Method, Abstract Factory, Factory Method
- Bridge, Builder
- Flyweight
- No Effect 3 patterns
- Interpreter, State, Façade
14
6
21Results
- Separation of Concerns (SoC)
- Increased Separation
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Decreased Separation
- Template Method, Abstract Factory, Factory Method
- Bridge, Builder
- Flyweight
- No Effect 3 patterns
- Interpreter, State, Façade
14
22Results - SoC
- Increased Separation for CDC, CDO, CDLOC
- E.g. CDLOC measures
CDLOC
23Results
- Separation of Concerns (SoC)
- Increased Separation 14 patterns
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Decreased Separation 6 patterns
- Template Method, Abstract Factory, Factory Method
- Bridge, Builder
- Flyweight
- No Effect 3 patterns
- Interpreter, State, Façade
best results
24Results - SoC
25Results - SoC
The measures of the AspectJ version do not
change as new elements are introduced superior
scalability
26Results
- Separation of Concerns
- Increased Separation 14 patterns
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Similar characteristics
- Superior even in simple pattern instances
- Most of these patterns are directly supported by
AspectJ features (e.g. Adapter)
best results
27Results
- Separation of Concerns
- Increased Separation 14 patterns
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Decreased Separation 6 patterns
- Template Method, Abstract Factory, Factory Method
- Bridge, Builder
- Flyweight
- No Effect 3 patterns
- Interpreter, State, Façade
improved SoC only after the changes
28Results - SoC
AspectJ implementations were superior only after
the introduced changes
Number of Components
Number of Operations
Number of Transition Points
29Results - SoC
The measures of the AspectJ version do not
change as new elements are introduced
Number of Components
Number of Operations
Number of Transition Points
30Results
- Separation of Concerns
- Increased Separation 14 patterns
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Similar characteristics
- Superior only in complex pattern instances
- Richer reusable aspects
- more of operations
- more of LOCs
improved SoC only after the changes
31Results - SoC
- Separation of Concerns
- Increased Separation 14 patterns
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Decreased Separation 6 patterns
- Template Method, Abstract Factory, Factory Method
- Bridge, Builder
- Flyweight
- No Effect 3 patterns
- Interpreter, State, Façade
overall improvements with exceptions
32Results - SoC
- Separation of Concerns
- Increased Separation 14 patterns
- Decorator, Adapter, Prototype, Visitor, Proxy,
Singleton - Mediator, Composite, Observer, Command, Iterator
- CoR, Strategy, and Memento
- Decreased Separation 6 patterns
- Template Method, Abstract Factory, Factory Method
- Bridge, Builder
- Flyweight
- No Effect 3 patterns
- Interpreter, State, Façade
33Results
- Separation of Concerns
- Decreased Separation 6 patterns
- Template Method, Abstract Factory, Factory
Method,Bridge, Builder - Flyweight
- Similar characteristics
- The pattern roles are nicely realized in OO
- Similar structure
- an additional aspect to replace abstract classes
with interfaces - not intended to separate the pattern roles
few differences
34Results - SoC
- Separation of Concerns (SoC)
- Decreased Separation 6 patterns
- Template Method, Abstract Factory, Factory
Method,Bridge, Builder - Flyweight
- Characteristics
- The AO structure is similar to the OO structure
- no advice/pointcut
- the generic aspect could be implemented as a
simpler class
high superiority for the OO design more than 33
35Results
- Coupling, Cohesion and Size
- Better Results for AO Solutions 5 patterns
- Composite, Observer, Adapter, Mediator, and
Visitor - Better Results for AO Solutions with Exceptions
4 patterns - Decorator, Proxy, Singleton, and State
- Better Results for OO Solutions with Exceptions
4 patterns - CoR, Command, Prototype, and Strategy
- Better Results for OO Solutions 8 patterns
- Template Method, Abstract Factory, Bridge,
Interpreter, - Factory Method, Builder, Memento, and Flyweight
- No Effect 2 patterns
- Iterator and Façade
9
12
36Results
- Coupling, Cohesion and Size
- Better Results for AO Solutions 5 patterns
- Composite, Observer, Adapter, Mediator, and
Visitor - Better Results for AO Solutions with Exceptions
4 patterns - Decorator, Proxy, Singleton, and State
- Better Results for OO Solutions with Exceptions
4 patterns - CoR, Command, Prototype, and Strategy
- Better Results for OO Solutions 8 patterns
- Template Method, Abstract Factory, Bridge,
Interpreter, - Factory Method, Builder, Memento, and Flyweight
- No Effect 2 patterns
- Iterator and Façade
37Results
a decorator aspect is coupled to all other
decorator aspects declare precedence
- ? AO Solutions exceptions
38Results
- Coupling, Cohesion and Size
- Better Results for AO Solutions 5 patterns
- Composite, Observer, Adapter, Mediator, and
Visitor - Better Results for AO Solutions with Exceptions
4 patterns - Decorator, Proxy, Singleton, and State
- Characteristics
- good separation of concerns (exception State)
- ? positive impact
- overall improvements for coupling,
inheritance,complexity of operations...
39Results
- Coupling, Cohesion and Size
- Better Results for OO Solutions with Exceptions
4 patterns - CoR, Command, Prototype, and Strategy
- Better Results for OO Solutions 8 patterns
- Template Method, Abstract Factory, Bridge,
Interpreter, - Factory Method, Builder, Memento, and Flyweight
40Results
- Coupling, Cohesion and Size
- Better Results for OO Solutions with Exceptions
- CoR, Command, Prototype, and Strategy
- Characteristics
- good separation of concerns
- no improvements for coupling, cohesion,inheritanc
e,...
41Results
- Coupling, Cohesion and Size
- Better Results for OO Solutions with Exceptions
4 patterns - CoR, Command, Prototype, and Strategy
- Better Results for OO Solutions 8 patterns
- Template Method, Abstract Factory, Bridge,
Interpreter, - Factory Method, Builder, Memento, and Flyweight
42Results
these patterns are already nicelyrealized in OO
43Outline
- The Problem
- Hannemann Kiczales Study
- Our Study Setting
- Metrics
- Assessment Procedures
- Results
- Separation of Concerns
- Coupling, Cohesion and Size
- Discussions
- General Analysis
- Study Constraints
- Conclusion
44General Analysis
- Separable and Inseparable Concerns
- SoC Improvements
- Our study 14 patterns
- HK study 17 patterns
- Contradictions Template Method, Flyweight, and
State - Template Method it does not seem reasonable or
even possible to isolate the pattern roles - Flyweight the AO and OO implementations are
similar - State the differences are not expressive
- Roles are expressed as aspects, but it remains
non-trivial to specify the combination in a
simple manner - E.g. Memento, Strategy, and CoR
- HK claims qualified the AspectJ implementations
as superior
45General Analysis
- Reducing Coupling and Increasing Cohesion
- aspects succeeded in the patterns with high
interaction between the roles - aspects modularize the collaboration protocol
involving the roles - E.g. Mediator, Observer, State, Composite, and
Visitor - Expressive Reusability only 4 patterns
- The HK study has found that 12 AspectJ versions
of the patterns are reusable
46General Analysis
- Aspects vs. Size Attributes
- 10 patterns fewer attributes in the AO version
- 12 patterns reduced of operations and
parameters - Metrics were useful to detect opportunities for
refactoring - Prototype interface declaration in the business
classes - CoR and Memento initializations
- Flyweight OO AO
47Study Constraints
- Limitations of some traditional metrics
- LOC
- Limited size and complexity of the examples
- Restrict the extrapolation of the results
- Assessment specific to the pattern instances at
hand
48Conclusion
- Most AspectJ implementations improved separation
of pattern-specific concerns - Aspect-oriented solutions of the patterns
significantly impacted on - Coupling and cohesion
- Size attributes of components, of
operations, of parameters, of attributes, ... - SoC cannot be taken as the only factor to
conclude for the use of aspects
49Modularizing Design Patterns with AspectsA
Quantitative Study
- Alessandro Garcia Cláudio SantAnna Eduardo
Figueiredo - Uirá Kulesza Carlos Lucena Arndt von Staa
- PUC-Rio, Brazil
March 2005
Now at Lancaster University, UK
50Publications
- Assessment of 7 patterns.
- C. SantAnna, A. Garcia, U. Kulesza, C. Lucena,
A. von Staa. Design Patterns as Aspects A
Quantitative Assessment. XVIII Brazilian
Symposium on Software Engineering (SBES04),
BrasÃlia, Brasil, October 2004. (Best Paper
Award) - Assessment of all the 23 patterns.
- A. Garcia, C. SantAnna, E. Figueiredo, U.
Kulesza, C. Lucena, A. von Staa. Modularizing
Design Patterns with Aspects A Quantitative
Study. Intl. Conference on Aspect-Oriented
Software Development (AOSD'05), Chicago, USA,
March 2005.
51References
- The Architectural Method
- TAO The Conceptual Framework
GARCIA, A. LUCENA, C. COWAN, D. Agents in
Object-Oriented Software Engineering. Software
Practice and Experience, Elsevier, May 2004, pp.
1-32.
?
GARCIA, A. et al. An Aspect-Based Approach for
Developing Multi-Agent Object-Oriented Systems.
Proceedings of the 15th Brazilian Symposium on
Software Engineering, Rio de Janeiro, Brazil,
October 2001, pp. 177-192. (Nomination for the
Best Paper Award)
?
SILVA, V. GARCIA, A. BRANDÃO, A. CHAVEZ, C.
LUCENA, C. ALENCAR, P. Taming Agents and Objects
in Software Engineering. In Software Engineering
for Large-Scale Multi-Agent Systems,
Springer-Verlag LNCS 2603, Berlin, April 2003.
?
52References
GARCIA, A. et al. Engineering Multi-Agent Systems
with Aspects and Patterns. Journal of the
Brazilian Computer Society, Special Issue on
Software Engineering and Databases, N. 1, Vol. 8,
July 2002, pp. 57-72.
?
GARCIA, A. et al. Separation of Concerns in
Multi-Agent Systems An Empirical Study. In
Software Engineering for Multi-Agent Systems II,
Springer-Verlag, LNCS 2940, March 2004, pp. 49-72.
?
CHAVEZ, C. GARCIA, A. LUCENA, C. Some Insights
on the Use of AspectJ and Hyper/J. Proceedings of
the Tutorial and Workshop on Aspect-Oriented
Programming and Separation of Concerns,
Lancaster, UK, August 2001
?
53References
- The Assessment Framework
- The Aspect-Oriented Agent Architecture
- The Pattern Language
SANT'ANNA, C. GARCIA, A. CHAVEZ, C. LUCENA,
C. VON STAA, A. On the Reuse and Maintenance of
Aspect-Oriented Software An Assessment
Framework. Proceedings of 17th Brazilian
Symposium on Software Engineering, Manaus,
Brazil, October 2003.
?
GARCIA, A. et al. Separation of Concerns in
Multi-Agent Systems An Empirical Study. In
Software Engineering for Multi-Agent Systems II,
Springer, LNCS 2940, March 2004, pp. 49-72.
?
GARCIA, A. KULESZA, U. LUCENA, C. Separation of
Concerns in Open Multi-Agent Systems An
Architectural Approach. Submitted to SELMAS04
workshop at ICSE04, Edinburgh, Scotland, May
2004.
?
GARCIA, A. KULESZA, U. LUCENA, C. From Objects
to Agents An Aspect-Oriented Pattern Language.
Submitted to ACM Transactions on Software
Engineering Methodologies.
?