Presentation is loading. Please wait.

Presentation is loading. Please wait.

19.12.2006 1 Aspect Oriented Programming Gülşah KARADUMAN.

Similar presentations


Presentation on theme: "19.12.2006 1 Aspect Oriented Programming Gülşah KARADUMAN."— Presentation transcript:

1 19.12.2006 1 Aspect Oriented Programming Gülşah KARADUMAN

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

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

4 4 19.12.2006 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 5 19.12.2006 Modularity Abstraction Decomposition Encapsulation Information Hiding Separation of Concerns  Low coupling  High cohesion

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

7 7 19.12.2006 Separation of Concerns Cohesion  Maximize cohesion within a component Coupling  Minimize coupling between components

8 8 19.12.2006 Separation of Concerns Advantages  Understandability  Reusability  Extensibility  Maintainability  Adaptability

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

10 10 19.12.2006 Crosscutting, Scattering, and Tangling Crosscutting  Concerns inherently relating to multiple components Scattering  Single concern affecting multiple modules Tangling  Multiple concerns interleaved in a single module

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

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

13 13 19.12.2006 Cost of Crosscutting Concerns Reduced understandability Decreased adaptability Decreased reusability Decreased maintainability

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

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

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

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

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

19 19 19.12.2006 Steps of AOP

20 20 19.12.2006 Programming with Aspects Writing the components Writing the aspects Weaving

21 21 19.12.2006 Aspect Weaving

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

23 23 19.12.2006 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 24 19.12.2006 AspectJ Terminology Join point Pointcut Advice Introduction Aspect

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

26 26 19.12.2006 Pointcuts A named collection of join points Designate join points

27 27 19.12.2006 Advice Before advice After advice Around advice

28 28 19.12.2006 Introduction Modifies  Members of a class  Relationship between classes

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

30 30 19.12.2006 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 { private int _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”); } Example – Without AOP Tangling Code Scattered Concern class Tracer { static void traceEntry(String str) { System.out.println(str); } static void traceExit(String str) { System.out.println(str); } }

31 31 19.12.2006 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 { private int _x = 0, _y = 0; int getX() { return _x; } int getY() { return _y; } void setX(int x) { _x = x; } void setY(int y) { _y = y; } Example - AspectJ aspect Tracing { pointcut traced(): call(* Line.* || call(* Point.*); before(): traced() { println(“Entering:” + thisjopinpoint); after(): traced() { println(“Exit:” + thisjopinpoint); void println(String str) { } } pointcut advice aspect Aspect is defined in a separate module Crosscutting is localized No scattering; No tangling Improved modularity

32 32 19.12.2006 Advantages of AOP  Tractability  Simpler cleaner code  Reusability  Easier to maintain

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

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

35 35 19.12.2006 References http://fsl.cs.uiuc.edu/images/9/9c/Kiczales 97aspectoriented.pdf http://en.wikipedia.org/wiki/Aspect- oriented_programming http://www.developer.com/design/article.p hp/3308941

36 36 19.12.2006 Thank you for your attention! Questions?


Download ppt "19.12.2006 1 Aspect Oriented Programming Gülşah KARADUMAN."

Similar presentations


Ads by Google