1 / 28

Aspect Oriented Programming

Aspect Oriented Programming. Scott Nykl CSSE 411 Senior Seminar. Overview. Motivation for Aspect Oriented Programming What is Aspect Oriented Programming? How Does Aspect Oriented Programming Work? Case Study. Motivation for Aspect Oriented Programming. First Computer Programs

Télécharger la présentation

Aspect Oriented Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Aspect Oriented Programming Scott Nykl CSSE 411 Senior Seminar

  2. Overview • Motivation for Aspect Oriented Programming • What is Aspect Oriented Programming? • How Does Aspect Oriented Programming Work? • Case Study

  3. Motivation for Aspect Oriented Programming • First Computer Programs • Consisted of cryptic binary strings

  4. Motivation for Aspect Oriented Programming • Next Generation • “Higher-Level” Assembly

  5. Motivation for Aspect Oriented Programming • 1957: Birth of Real “High-Level” Language • IBM’s Fortran • Division created between a computer’s hardware and the coupling that hardware imposed upon the software. • Subprograms, or subroutines • Modular code blocks allowed decomposition into smaller pieces • Increased reusability and maintainability of code

  6. Motivation for Aspect Oriented Programming • Late 1960s: Object Oriented Paradigm • Collection of related data and operations useful to that data • Paved way for Modern C++, Java, C#, etc.

  7. Motivation for Aspect Oriented Programming • Problems with OO • Although specific groups of data and operations are cohesively grouped together, other secondary operations still need to be duplicated across these objects. • High-level, system-wide requirements • Application logging • Security requirements • Other Policy Layer Requirements

  8. Motivation for Aspect Oriented Programming • General Application-wide requirements still need to be supported via these objects but are not explicitly encapsulated in one single object type

  9. Motivation for Aspect Oriented Programming • Assume following scenario • Employee record system • Collection of employee related objects • Each object has cohesive set of operations that perform necessary manipulations on the data contained within that object

  10. Motivation for Aspect Oriented Programming • Employee Record System • Now imagine that the system is extended to support logging each employee change to a logging database.

  11. Motivation for Aspect Oriented Programming • OO Approach • Developers will have to • Dive inside the employee objects • Add additional operations to support logging • Wading through existing code and finding the exact locations to insert logging operations can be a time-consuming, tedious, and error-prone process which can lead to software instability and security flaws. • Writing to a database, or ensuring sufficient privileges are obtained does not coherently fit with what employee objects represent – BAD COHESION (Dr. Rowe = Angry)

  12. What Is Aspect Oriented Programming? • Solution = Aspect Oriented Approach • We want to add new functionality in a single location and simply specify that this new functionality is to be invoked when certain conditions arise. • Added functionality is achieved without wading through existing code and appending duplicate functionality across existing operations.

  13. What Is Aspect Oriented Programming? • Employee Record System • We will be able to create one central collection of operations responsible for logging to a database • Specify that a database write shall be invoked when an employee object is modified.

  14. How Does Aspect Oriented Programming Work? • Cross-Cutting Concern: Some aspects of implementation, such as logging, error handling, standards enforcement, and policy-layer modification are difficult to implement in a modular way. The result is that code is tangled across a system; this leads to quality, productivity, and maintenance issues. These issues are cross-cutting concerns

  15. How Does Aspect Oriented Programming Work? • Advice: This is the additional code that one wants to apply to an existing model to add support for features such as logging, error handling, standards enforcement, and policy-layer modification

  16. How Does Aspect Oriented Programming Work? • Point Cut: This is the term given to the point of execution in the application at which a cross-cutting concern needs to be applied. In our example, a point-cut is reached when a thread of execution within the employee record system enters a method responsible for modifying an employee; a second point-cut is reached when that thread of execution leaves the method responsible for modifying an employee

  17. How Does Aspect Oriented Programming Work? • Aspect: The combination of the point-cut and the advice is termed an aspect. In our example, we add a logging aspect to our employee record system by defining a point-cut and giving the correct advice to execute when that point-cut is reached = +

  18. aspect vs class aspect specific data and operations are “static” aspect is a singleton pointcut declaration advice

  19. How Does Aspect Oriented Programming Work? • Point-cut named “LogEmployeeChange” • Specify specific points where employee object changed • Deals only with objects of type “Employee” (line 13) • Deals specifically with 4 methods contained within the “Employee” class (lines 14-17) • Line 14 explicitly says, “for any ‘public’ method of class ‘Employee’ with any type of return parameter (‘*’), a name of ‘setName’, and a parameter set of anything (‘..’), execute the corresponding Advice • Note: use of wildcards allow the aspect programmer to include a large grouping of functions in a single line.

  20. How Does Aspect Oriented Programming Work? • before Advice • Line 19 says, “Since my associated point-cut has been triggered, execute the code in my block before executing the method which triggered the point-cut.” • The actual instance of the Employee class which will be modified is passed into the before Advice as “Employee e”; the advice can modify Employee e.

  21. How Does Aspect Oriented Programming Work? • After executing before Advice, the method which triggered the point-cut is executed; this method could be “setName”, “setAddress”, etcetera. • Once execution returns from this method, the after Advice is considered.

  22. Case Study: Apache Tomcat • Tomcat: open-source implementation of Java Servlet and JavaServer Pages developed at the Apache Software Foundation. • Object-Oriented

  23. Case Study: Apache Tomcat • Red Shows encapsulated XML Parser in Tomcat

  24. Case Study: Apache Tomcat • Red Shows encapsulated URL Pattern Matching in Tomcat

  25. Case Study: Apache Tomcat • Red Shows Tomcat Logging • A single logging aspect can replace this tangle • Increase Cohesion • Decrease Coupling • Increase Maintainability • No duplicated logging code across multiple classes

  26. Summary • AspectJ and Aspect-Oriented Programming represent a way to cleanly modularize high-level requirements which span across the scope of many different classes and operations. Using AspectJ can greatly alleviate issues related to logging, monitoring, application-spanning requirements, and many other issues that commonly cause headaches for even well-designed Object-Oriented systems

More Related