Aspect Oriented Software Development


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Aspect Oriented Software Development

    1. 1. Aspect-Oriented Software Development (AOSD) Jignesh Patel Jignesh.Patel [AT] umkc [DOT] edu
    2. 2. Background <ul><li>Evolution of software programming methodology </li></ul><ul><ul><li>Machine-Level coding </li></ul></ul><ul><ul><li>Structured Programming </li></ul></ul><ul><ul><li>Object-Oriented Programming </li></ul></ul><ul><li>Programming methodology </li></ul><ul><ul><li>defines the way we communicate with machines. </li></ul></ul><ul><ul><li>presents new ways to decompose problems – </li></ul></ul><ul><ul><ul><li>Machine-code, machine-independent code, procedures, classes and so on… </li></ul></ul></ul><ul><ul><li>provides a more natural mapping of system requirements to programming constructs. </li></ul></ul>
    3. 3. Background <ul><li>Object-Oriented Programming </li></ul><ul><ul><li>Set of collaborating objects. </li></ul></ul><ul><ul><li>Hide implementation details in Classes. </li></ul></ul><ul><ul><li>Common behavior for related concepts using Polymorphism </li></ul></ul><ul><ul><li>Favorite Choice for developing most new software projects. Why? </li></ul></ul><ul><ul><ul><li>Allowed us to deal with complex software projects. </li></ul></ul></ul><ul><ul><li>But OOP is not the panacea </li></ul></ul>
    4. 4. Background <ul><li>Limitations of Object-Oriented Programming </li></ul><ul><ul><li>Requirements do not decompose into behavior centered on a single locus. </li></ul></ul><ul><ul><li>difficulty localizing concerns involving global constraints and pandemic behaviors, </li></ul></ul><ul><ul><li>appropriately segregating concerns, and applying domain-specific knowledge. </li></ul></ul><ul><li>Post-object programming (POP) mechanisms that look to </li></ul><ul><ul><li>Increase the expressiveness of the OO paradigm </li></ul></ul><ul><ul><li>are a fertile arena for current research. </li></ul></ul><ul><ul><li>Examples of POP technologies include </li></ul></ul><ul><ul><ul><li>domain-specific languages, generative programming, generic programming, constraint languages, reflection and metaprogramming, feature-oriented development. </li></ul></ul></ul>
    5. 5. History <ul><li>Aspect-Oriented Programming (AOP) </li></ul><ul><ul><li>Latest entrant in programming methodologies </li></ul></ul><ul><ul><li>Represents one facet of Aspect-Oriented Software Development (AOSD) </li></ul></ul><ul><ul><li>Attributed to Greger Kiczales et al., </li></ul></ul><ul><ul><ul><li>University of British Columbia </li></ul></ul></ul><ul><ul><ul><li>Works on software modularity research </li></ul></ul></ul><ul><ul><ul><li>Leader in the development and implementation of AOP at Xerox Palo Alto Research Center (PARC) from 1984 - 1999 </li></ul></ul></ul>
    6. 6. Why AOP? – Example You are responsible for maintaining large software system that managed payroll and personnel functions for your organization. What if management issued a new requirement ? “ create a log of all changes to an employee’s data” <ul><li>This would include changes in – </li></ul><ul><li>Payroll </li></ul><ul><li>Number of deductions </li></ul><ul><li>Raises </li></ul><ul><li>Employee’s personal data </li></ul><ul><li>100s of many other information associated with employee </li></ul>What would you do?
    7. 7. Aspect-Oriented Programming <ul><li>Computer systems are better programmed by separately specifying the various “concerns” </li></ul><ul><li>Concerns : properties or areas of interests </li></ul><ul><ul><li>High-level – security, QoS </li></ul></ul><ul><ul><li>Low-level – caching, buffering </li></ul></ul><ul><ul><li>Functional – features, business rules </li></ul></ul><ul><ul><li>Non Functional (systemic) – synchronization, transaction management. </li></ul></ul>
    8. 8. System = set of “concerns” <ul><li>A typical system may consist of several kind of concerns including – </li></ul><ul><ul><li>Business logic </li></ul></ul><ul><ul><li>Performance </li></ul></ul><ul><ul><li>Data persistence </li></ul></ul><ul><ul><li>Logging and Debugging </li></ul></ul><ul><ul><li>Authentication </li></ul></ul><ul><ul><li>Security </li></ul></ul><ul><ul><li>Multi-threaded safety </li></ul></ul><ul><ul><li>Error-checking </li></ul></ul><ul><ul><li>and so on… </li></ul></ul>
    9. 9. Concerning “Concerns” <ul><li>Why they are difficult to program? </li></ul><ul><ul><li>Some concerns are neatly localized within specific structural piece, </li></ul></ul><ul><ul><li>Others tend to scatter and cross multiple elements. </li></ul></ul><ul><ul><ul><li>aka “Crosscutting Concerns” </li></ul></ul></ul><ul><li>Problems </li></ul><ul><ul><li>Not every concern fits into a component: crosscutting </li></ul></ul><ul><ul><li>Two issues: </li></ul></ul><ul><ul><ul><li>Implementation for authentication, contract checking and logging is not localized. </li></ul></ul></ul><ul><ul><ul><ul><li>Code spans over many methods of potentially many classes and packages. </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>aka Code Scattering </li></ul></ul></ul></ul></ul><ul><ul><ul><li>Implementation of someOperation() does much more than performing some core functionality. </li></ul></ul></ul><ul><ul><ul><ul><li>It contains code for more than one concerns. aka Code tangling </li></ul></ul></ul></ul>
    10. 10. Crosscutting Concerns <ul><li>Implementation Modules becomes mess when we code these concerns </li></ul>Performance
    11. 11. Aspect-Oriented Programming <ul><li>AOP is designed to handle crosscutting concerns by providing a mechanism known as aspect </li></ul><ul><li>Aspects </li></ul><ul><ul><li>Express these concerns and automatically incorporates them into a system. </li></ul></ul><ul><ul><li>Enhances the ability to express separation of these concerns. </li></ul></ul><ul><ul><li>Leads to well-designed, maintainable software system. </li></ul></ul><ul><li>AOP doesn’t replace existing programming paradigms and languages. </li></ul><ul><li>Instead it works with them to improve their expressiveness and utility. </li></ul>
    12. 12. Aspect-Oriented Programming components and aspect descriptions weaver (compile-time) Source Code (tangled code)
    13. 13. AOSD Tools <ul><li>abc is a full implementation of the AspectJ language, with an emphasis on extensibility and optimisations. </li></ul><ul><li>Aspect# is a free AOP framework for .NET. </li></ul><ul><li>AspectC++ is an aspect-oriented extension to the C++ programming language. </li></ul><ul><li>AspectDNG is a .NET multi-language aspect weaver. </li></ul><ul><li>AspectJ is a seamless aspect-oriented extension to Java that enables the modular implementation of a wide range of crosscutting concerns. </li></ul><ul><li>AspectWerkz is a dynamic, lightweight and high-performant AOP/AOSD framework for Java. </li></ul><ul><li>AspectXML is an attempt to sound out, brainstorm, and generally try out the aspect oriented approach in relation to XML. </li></ul><ul><li>JAC is a Java framework for aspect-oriented distributed programming. </li></ul><ul><li>JBoss-AOP is the Java AOP architecture used for the JBOSS application server. </li></ul><ul><li>LOOM.NET is a static aspect weaver that operates on binary .NET assemblies. The RAPIER-LOOM.NET library is a dynamic aspect weaver. </li></ul><ul><li>Nanning is an Aspect Oriented Framework for Java based on dynamic proxies and aspects implemented as ordinary Java-classes. </li></ul><ul><li>Spring 's approach to AOP differs from that of most other AOP frameworks. The aim is not to provide the most complete AOP implementation (although Spring AOP is quite capable); it is rather to provide a close integration between AOP implementation and Spring IoC to help solve common problems in enterprise applications. </li></ul><ul><li>XWeaver is an extensible, customizable and minimally intrusive aspect weaver for C/C++ — it generates source code which differs as little as possible from the base code (preserves layout and comments). </li></ul>
    14. 14. Logging example in AspectJ <ul><li>Three steps to program using AspectJ </li></ul><ul><ul><li>Identify places in the code where we want to insert the logging code. This is called defining join points in AspectJ. </li></ul></ul><ul><ul><li>Write the logging code. </li></ul></ul><ul><ul><li>Compile the new code and integrate it into the system. </li></ul></ul>
    15. 15. Logging Example – Step1 <ul><li>Define the join points </li></ul><ul><ul><li>A join point is a well-defined point in the code at which our concerns crosscut the application. </li></ul></ul><ul><ul><li>In AspectJ, we define join points by grouping them into pointcuts . </li></ul></ul>
    16. 16. Logging Example – Step2 <ul><li>Write the Logging code </li></ul><ul><ul><li>In AspectJ, we define what to do by grouping them into advice . </li></ul></ul><ul><ul><ul><li>three kinds of advice : before , after and around </li></ul></ul></ul>
    17. 17. Logging Example – Step3 <ul><li>Compile and Test </li></ul><ul><ul><li>This code runs just fine without any AOP implementation </li></ul></ul>Output:
    18. 18. Logging Example – Step3 <ul><li>Compile and Test </li></ul><ul><ul><li>incorporate our aspect into the system, we add the aspect source code to the project and build with the AspectJ compiler, ajc </li></ul></ul><ul><ul><li>The compiler takes each aspect </li></ul></ul><ul><ul><ul><li>creates class files that contain the advice code. </li></ul></ul></ul><ul><ul><ul><li>calls to the appropriate methods in these class files are woven into the original application code </li></ul></ul></ul><ul><ul><li>In AspectJ this is done at Java bytecode level </li></ul></ul>Output: Lets play “ starwars ”
    19. 19. Recap of AOP Separation of concerns (monitoring, synchronisation, debugging, security, etc.) Where What MyAspect In MyProgram Before process { display data print “before process” } MyProgram collect data process data display result Weaver Synchronisation Aspect Business code Classes Monitor Aspect Tangled Classes, Crosscutting Concerns synchronisation monitoring MyProgram collect data display data print “before process” process data display result
    20. 20. What does all these mean? <ul><li>AOP has many potential benefits </li></ul><ul><ul><li>provides a way of specifying and encapsulating cross-cutting concerns in a system. </li></ul></ul><ul><ul><li>allow us to do a better job of maintaining systems as they evolve </li></ul></ul><ul><ul><li>let us add new features, in the form of concerns, to existing systems in an organized manner. </li></ul></ul><ul><ul><li>improvements in expressiveness and structure helps us to keep systems running longer, without incurring the expense of a complete rewrite. </li></ul></ul><ul><ul><li>a great addition to quality professionals’ toolboxes. Ability to test application code automatically without disturbing the code. </li></ul></ul>
    21. 21. AOP – a prism analogy
    22. 22. Early Aspects & AOSD research <ul><li>Early Aspects </li></ul><ul><ul><li>Separating aspects and concerns at early stages of software development life cycle. </li></ul></ul><ul><li>Main AOSD research interests: </li></ul><ul><ul><li>Semantics of AO Languages and Formal Methods </li></ul></ul><ul><ul><ul><li>(Composition, Join point, Pointcuts, Advices, Weaving) </li></ul></ul></ul><ul><ul><li>Aspects in Early Life cycle Steps </li></ul></ul><ul><ul><li>Design of concerns </li></ul></ul><ul><ul><li>Dynamic Aspects and Infrastructure Software </li></ul></ul>
    23. 23. Among the Most Popular downloads <ul><li>©2005 ACM 0001-0782/05/0400 $5.00 </li></ul><ul><li>Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. </li></ul>Communications of the ACM, Volume 48, No 4 (Apr 2005), Pages 33-34
    24. 24. Conclusion <ul><li>AOP </li></ul><ul><ul><li>Modularized implementation of crosscutting concerns </li></ul></ul><ul><ul><li>Easier-to-evolve systems </li></ul></ul><ul><ul><li>Late binding of design decisions </li></ul></ul><ul><ul><li>More code reuse </li></ul></ul><ul><li>If software system comprises of crosscutting concerns consider learning more about AOP </li></ul>
    25. 25. Latest AOSD conference (2005, March 22-26, Chicago, Illinois) <ul><li>Using AspectJ to Build a Product Line for Mobile Devices </li></ul><ul><li>Developing Embedded Software Product Lines with AspectC++ </li></ul><ul><li>Aspect-Oriented Programming with Caesar </li></ul><ul><li>Developing Dynamic and Adaptable Applications with CAM/DAOP: A Virtual Office Application </li></ul><ul><li>PROSE - A middleware platform for dynamic adaptation </li></ul><ul><li>Microsoft Phoenix: A Framework for Software Analysis and Optimization </li></ul>
    26. 26. References <ul><li>Many tools, papers, and other resources related to aspect-oriented software development here: http:// </li></ul><ul><li>Read more about Xerox's AspectJ, a free AOP implementation for Java: http:// </li></ul><ul><li>Ramnivas Laddad's &quot;XML APIs for Databases&quot; ( JavaWorld, January 2000) explains how to blend the power of XML and databases using custom SAX and DOM APIs : </li></ul><ul><li>Communications of the ACM , October 2001, has many articles on AOSD </li></ul><ul><li>Past AOSD Conferences </li></ul><ul><ul><li> </li></ul></ul><ul><li>Grundy, J. “Aspect-oriented Requirements Engineering for Component-based Software Systems”, 4th IEEE International Symposium on Requirements Engineering, IEEE Computer Society, Limerick, Ireland, 1999, pp. 84-91 </li></ul><ul><li>IBM Research. MDSOC: Software Engineering Using Hyperspaces, http:// /hyperspace/ </li></ul><ul><li>Moreira, A., Araújo, J., Brito, I. “Crosscutting Quality Attributes for Requirements Engineering”, 14th International Conference on Software Engineering and Knowledge Engineering (SEKE 2002), ACM Press, Italy, July 2002. </li></ul><ul><li>Rashid, A., Sawyer, P., Moreira, A. and Araújo, J. “Early Aspects: a Model for Aspect-Oriented Requirements Engineering”, IEEE Joint Conference </li></ul><ul><li>Workshop on “Aspect-oriented Modeling with UML”. </li></ul><ul><li>Workshop on “Early Aspects: Aspect-Oriented Requirements Engineering and Architecture Design”. </li></ul>