Aspect Oriented Programming Meets Design Patterns
Total Page:16
File Type:pdf, Size:1020Kb
ASPECT ORIENTED PROGRAMMING MEETS DESIGN PATTERNS A dissertation submitted to The University of Manchester for the degree of Master of Science in the Faculty of Engineering and Physical Sciences 2013 GUILLERMO A. TORO BAYONA SCHOOL OF COMPUTER SCIENCE List of Contents ABSTRACT ............................................................................................................ 8 DECLARATION ....................................................................................................... 9 INTELLECTUAL PROPERTY STATEMENT .................................................................. 10 1 INTRODUCTION ............................................................................................. 11 1.1 Project Objectives ................................................................................ 11 1.2 Dissertation Overview ......................................................................... 12 2 BACKGROUND .............................................................................................. 14 2.1 Object Oriented Programming ............................................................. 14 2.2 Design Patterns ................................................................................... 15 2.3 Object Oriented Programming and Design Pattern Issues .................. 15 2.4 A Simple Application with OOP ........................................................... 16 2.4.1 The Observer Pattern ................................................................... 17 2.4.2 Code Implementation ................................................................... 19 2.4.3 Issues Analysis ............................................................................. 22 2.5 Aspect Oriented Programming ............................................................ 24 2.5.1 Relevant Concepts ....................................................................... 24 2.5.2 Development Process with Aspects .............................................. 25 2.6 A Simple Example with AOP ............................................................... 26 2.6.1 Code Implementation ................................................................... 26 2.6.2 Simple Scenario Analysis ............................................................. 27 2.7 The Aspect Oriented Paradigm and Software Development ............... 29 2.7.1 AOP and Software Development Process .................................... 29 2.7.2 Development ................................................................................ 29 2.7.3 Testing .......................................................................................... 30 2.7.4 Unified Modelling Language and AOP .......................................... 30 2.7.5 Design Patterns ............................................................................ 31 3 RESEARCH METHODS ................................................................................... 33 3.1 Aspect Oriented Programming meets Design Patterns ....................... 33 3.2 Metrics ................................................................................................ 33 3.3 Aspect J (Aspect Implementation for Java) ......................................... 35 3.4 Project Methodology ........................................................................... 36 2 3.4.1 Explore a subset of the patterns to apply. ..................................... 36 3.4.2 Develop an application using OOP and AOP. ............................... 36 3.4.3 Assess and review the metrics. .................................................... 37 3.4.4 Identify advantages and disadvantages of AOP. ........................... 37 3.4.5 Document the results. ................................................................... 37 4 THE OBSERVER PATTERN ............................................................................. 38 4.1 Business Scenario .............................................................................. 38 4.2 AOP Implementation ........................................................................... 38 4.3 Metrics ................................................................................................ 41 4.4 Metrics Analysis .................................................................................. 43 4.5 Conclusions ......................................................................................... 46 5 THE COMPOSITE , ADAPTER AND PROXY PATTERNS ......................................... 48 5.1 Business Scenarios ............................................................................. 48 5.2 The Composite Pattern ....................................................................... 49 5.2.1 OOP Approach ............................................................................. 49 5.2.2 AOP Approach .............................................................................. 51 5.3 The Adapter Pattern ............................................................................ 53 5.3.1 OOP Approach ............................................................................. 53 5.3.2 AOP Approach .............................................................................. 54 5.4 The Proxy Pattern ............................................................................... 55 5.4.1 OOP Approach ............................................................................. 55 5.4.2 AOP Approach .............................................................................. 56 5.5 Metrics Analysis .................................................................................. 58 5.6 Conclusions ......................................................................................... 61 6 THE COMMAND , STRATEGY AND TEMPLATE PATTERNS .................................... 64 6.1 Business Scenarios ............................................................................. 64 6.2 The Command Pattern ........................................................................ 65 6.2.1 OOP Approach ............................................................................. 65 6.2.2 AOP Approach .............................................................................. 66 6.3 The Strategy Pattern ........................................................................... 68 6.3.1 OOP Approach ............................................................................. 68 6.3.2 AOP Approach .............................................................................. 69 6.4 The Template Pattern .......................................................................... 70 6.4.1 OOP Approach ............................................................................. 70 6.4.2 AOP Approach .............................................................................. 71 3 6.5 Metrics Analysis .................................................................................. 72 6.6 Conclusions ......................................................................................... 75 7 THE ABSTRACT FACTORY AND SINGLETON PATTERNS ..................................... 78 7.1 Business Scenarios ............................................................................. 78 7.2 The Abstract Factory Pattern ............................................................... 78 7.2.1 OOP Approach ............................................................................. 78 7.2.2 AOP Approach .............................................................................. 80 7.3 The Singleton Pattern ......................................................................... 81 7.3.1 OOP Approach ............................................................................. 81 7.3.2 AOP Approach .............................................................................. 83 7.4 Metrics Analysis .................................................................................. 84 7.5 Conclusions ......................................................................................... 86 8 PATTERN INTERACTIONS ............................................................................... 88 8.1 Overview ............................................................................................. 88 8.2 Pattern Dependencies ......................................................................... 88 8.2.1 Strategy and Observer patterns .................................................... 88 8.2.2 Abstract Factory and Singleton patterns ....................................... 90 8.2.3 Template and Proxy patterns ........................................................ 90 8.2.4 Composite pattern ........................................................................ 91 8.3 Domain Classes .................................................................................. 93 8.3.1 Monitoring Stations ....................................................................... 93 8.3.2 Local and Remote Stations ........................................................... 94 9 CONCLUSIONS AND FUTURE WORK ................................................................ 95 9.1 Conclusions ......................................................................................... 95 9.2 Recommendations .............................................................................. 97 9.3 Future Work ........................................................................................ 98 10 REFERENCES ............................................................................................