1 / 36

Aspect Oriented Programming

Aspect Oriented Programming . Gülşah KARADUMAN. Outline. Introduction The Problem Goal of AOP Programming with Aspects AspectJ Conclusions. Background Information. Functional decomposition Break the system into smaller units Programming languages

candy
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 Gülşah KARADUMAN

  2. Outline • Introduction • The Problem • Goal of AOP • Programming with Aspects • AspectJ • Conclusions

  3. Background Information • Functional decomposition • Break the system into smaller units • Programming languages • Define abstractions for the small units • Compose the units into systems

  4. Procedure Based Languages • Functional, Procedural, OO • Comfortable to talk about what is encapsulated as a functional unit of the overall system • What about the units of decomposition that are not functional

  5. Modularity • Abstraction • Decomposition • Encapsulation • Information Hiding • Separation of Concerns • Low coupling • High cohesion

  6. Concerns • Particular goal, concept, or area of interest • Primary motivation for organizing and decomposing software into manageable and comprehensible parts

  7. Separation of Concerns • Cohesion • Maximizecohesion within a component • Coupling • Minimize coupling between components

  8. Separation of Concerns • Advantages • Understandability • Reusability • Extensibility • Maintainability • Adaptability

  9. The Problem • Limitations of OOP • decomposition resulting in cross-cutting concerns • Insufficieny of OO and procedural development techniques

  10. Crosscutting, Scattering, and Tangling • Crosscutting • Concernsinherently relating to multiple components • Scattering • Single concern affecting multiple modules • Tangling • Multiple concerns interleaved in a single module

  11. Crosscutting Concern Examples • Synchronization • Real-time constraints • Error-checking • Object interaction constraints • Memory management • Persistency • Security • Caching • Logging • Monitoring • Testing • Domain specific optimization

  12. DisplayTracking Crosscutting Concern Examples Display * Figure FigureElement Point Line 2 getX() getY() getP1 setP1 setX(int) setY(int) setP1(Point) setP2(Point)

  13. Cost of Crosscutting Concerns • Reduced understandability • Decreased adaptability • Decreased reusability • Decreased maintainability

  14. Component • Cleanly encapsulated in a generalized procedure (i.e. object, method, procedure, API) • Well-localized, and easily accessed and composed

  15. Aspect • Properties that affect the performance or semantics of the components in systemic ways • Not cleanly encapsulated in a generalized procedure

  16. Goal of AOP • Separate components and aspects from each other • Abstract and compose the components and aspects to produce the overall system

  17. AOP • A promising new technology for separating crosscutting concerns that are usually hard to do in object-oriented programming

  18. Fundamentals of AOP • Aspect as a modularization unit • Three distinct development steps: • Aspectual decomposition • Concern implementation • Aspectual recomposition

  19. Steps of AOP

  20. Programming with Aspects • Writing the components • Writing the aspects • Weaving

  21. Aspect Weaving

  22. Tools for AOP • AspectJ • AspectC++ • AspectWerkz • JAC • JBoss-AOP • Nanning

  23. AspectJ • Small, well-integrated extension to Java • Java programs as input • .class files compatible with any JVM as output • Free and open source AspectJ compiler

  24. AspectJ Terminology • Join point • Pointcut • Advice • Introduction • Aspect

  25. Join Points • Well-defined points in a program's execution • Key points in dynamic call graph

  26. Pointcuts • A named collection of join points • Designate join points

  27. Advice • Before advice • After advice • Around advice

  28. Introduction • Modifies • Members of a class • Relationship between classes

  29. Aspect • Module for handling crosscutting concerns • Defined in terms of pointcuts, advice, and introduction • Reusable and inheritable

  30. Example – Without AOP class Line { private Point _p1, _p2; Point getP1() { return _p1; } Point getP2() { return _p2; } void setP1(Point p1) { Tracer.traceEntry(“entry setP1”); _p1 = p1; Tracer.traceExit(“exit setP1”); } void setP2(Point p2) { Tracer.traceEntry(“entry setP2”); _p2 = p2; Tracer.traceExit(“exit setP2”); } class Point { privateint _x = 0, _y = 0; int getX() { return _x; } int getY() { return _y; } void setX(int x) { Tracer.traceEntry(“entry setX”); _x = x; Tracer.traceExit(“exit setX”) } void setY(int y) { Tracer.traceEntry(“exit setY”); _y = y; Tracer.traceExit(“exit setY”); } } class Tracer { staticvoid traceEntry(String str) { System.out.println(str); } staticvoid traceExit(String str) { System.out.println(str); } } Tangling Code Scattered Concern

  31. pointcut advice Example - AspectJ aspect Tracing { pointcut traced(): call(* Line.* || call(* Point.*); before(): traced() { println(“Entering:” + thisjopinpoint); after(): traced() { println(“Exit:” + thisjopinpoint); void println(String str) {<write to appropriate stream>} } } aspect class Line { private Point _p1, _p2; Point getP1() { return _p1; } Point getP2() { return _p2; } void setP1(Point p1) { _p1 = p1; } void setP2(Point p2) { _p2 = p2; } } class Point { privateint _x = 0, _y = 0; int getX() { return _x; } int getY() { return _y; } void setX(int x) { _x = x; } void setY(int y) { _y = y; } } Aspect is defined in a separate module Crosscutting is localized No scattering; No tangling Improved modularity

  32. Advantages of AOP • Tractability • Simpler cleaner code • Reusability • Easier to maintain

  33. Disadvantages of AOP • Difficult to understand a software because of invisibly injected aspects • Fragile build problems • Complicated control flow breakage • Reduced quality ofsoftware if aspects are not appropriately managed

  34. Conclusions • Scattered crosscutting concerns over several modules causing tangling code • Explicit abstraction mechanism with AOP • Increased modularity of the system

  35. References • http://fsl.cs.uiuc.edu/images/9/9c/Kiczales97aspectoriented.pdf • http://en.wikipedia.org/wiki/Aspect-oriented_programming • http://www.developer.com/design/article.php/3308941

  36. Thank you for your attention! • Questions?

More Related