190 likes | 453 Views
Introduction to Aspect Oriented Programming. Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech. Contents. Introduction AOP Methodology AOP Languages AspectJ. Programming Methodologies. Introduction. Concern Abstraction. AO Programming. Object
E N D
Introduction toAspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Contents • Introduction • AOP Methodology • AOP Languages • AspectJ Aspect Oriented Programming
Programming Methodologies Introduction Concern Abstraction AO Programming Object Abstraction OO Programming Function Abstraction Procedural Programming Assembly Programming Programming Methodologies Evaluation m/c Programming Aspect Oriented Programming
Present Design Problem Introduction • The architect’s dilemma • How much design is too much? Aspect Oriented Programming
Terminology Introduction • Concern • A specific requirement or consideration that must be addressed in order to satisfy the overall system goal • E.g. Banking system: Customer and Account management, Interbanking transactions, ATM transactions, Persistence of all entities, Transaction integrity, Authorization of access to various services, Logging, Security, Error checking, Policy enforcement Aspect Oriented Programming
Terminology cont Introduction • Core concerns • Central functionality of a Business logic (single module) • Customer and Account management, Interbanking transactions, ATM transactions • Crosscut concerns • System-level, peripheral requirements (multiple modules) • Persistence of all entities, Transaction integrity, Authorization of access to various services, logging, Security, Error checking, Policy enforcement Aspect Oriented Programming
Typical Application Introduction Business Logic Concern Accounting ATM Persistence Logging Database Logging Implementation modules Persistence System Accounting ATM Database Logging Persistence System Aspect Oriented Programming
Implementation by Traditional Languages Introduction API invocations Accounting Module ATM Module Logging Module Database Module Aspect Oriented Programming
Implementation by AOP Introduction Automatically Weaving Invocations Accounting Module API Invocation Logging Aspect ATM Module Logging Module Aspect: A modular unit of crosscutting concern implementation Database Module Aspect Oriented Programming
AOP Methodology AOP Methodology • The idea behind AOP is “Separation of concern” • AOP builds upon Existing Methodologies (OOP, Procedural programming), augmenting them with concepts and constructs in order to modularize crosscutting concerns. • Now, concern consists of what? Aspect Oriented Programming
AOP Development Stages AOP Methodology Security Business Logic Logging Persistence Integrating all concerns Identify concerns Aspect Oriented Programming
AOP Languages AOP Languages • AOP Language Specification • Describes the language constructs and syntax • Specification for implementing the individual concerns and rules for weaving different concerns Aspect Oriented Programming
AOP Languages cont AOP Languages • AOP language implementation • Verifies the code and translates the code into an executable form • Implementation done by two steps • Combining individual concerns using the weaving rules - Weaving • Then converting result into executable code. • Some AOP Languages • AspectJ, Aspect#, AspectC++, PHPaspect. Aspect Oriented Programming
AspectJ AspectJ • Aspect-oriented extension to Java language • Language Specification • Language Implementation • Concern by Java Language • Weaving rules by extension Tools • Crosscutting in AspectJ • Implementation of the weaving rules by the compiler • 2 Types: • Dynamic Crosscutting • Weaving of new Behavior into execution of program • Static Crosscutting • weaving of modifications into the static structure, to support the Dynamic Crosscutting Aspect Oriented Programming
AspectJ cont AspectJ • Crosscutting Elements • Join Point • Well-defined points in the execution of a program • Pointcut • A means of referring to collections of join points and certain values at those join points • Advice • Method-like constructs to define additional behavior at join points • Introduction • Instruction that changes to the classes, interfaces of the system • Compile time Declaration • Instruction for adding compile time warnings and errors to the system • Aspect • Unit of modular crosscutting implementation Aspect Oriented Programming
Example AspectJ Public class Logging{//class public void check( ) { System.out.println("Inside Logging Class Method"); }} public class ATM { //class public void foo(int number, String name) { System.out.println("Inside foo Method"); } public static void main(String[] args) { MyClass myObject = new MyClass( ); myObject.foo(1, “SIT"); } } public aspect Log { //Aspect pointcut callPointcut( ) : call(void ATM.foo(int, String)); //Pointcut before( ) : callPointcut( ) { //Advice System.out.println( “I am from Log aspect"); Logging logg= new Logging(); logg.check(); } } Name of Pointcut before after around Aspect Oriented Programming
Example cont AspectJ • Compile • ajc ATM.java Log. java • output: • ATM.class Log.class • Run • java ATM • Output: • I am from Log aspect Inside foo Method Here let us assume Logging class already compiled Aspect Oriented Programming
References • AspectJ Cookbook , O'Reilly, December 2004 • Aspectj In Action - Practical Aspect-Oriented Programming, 2003 • http://www.codeproject.com/gen/design/aop.asp#2 • http://en.wikipedia.org/wiki/Aspect_oriented_programming • Erik Putrycz, Guy Bernard, IEEE 2002, Using Aspect Oriented Programming to build a portable load balancing service Aspect Oriented Programming