Survey of Aspect-Oriented Programming

Preview:

DESCRIPTION

Survey of Aspect-Oriented Programming. Neerja Bhatnagar. CS 203 Programming Languages Fall 2004. Motivation for AOP. Code continues to grow in size and complexity Code evolves to become unmodularized, and hence unclean Application logic gets intermingled with system code - PowerPoint PPT Presentation

Citation preview

Survey of Aspect-Oriented Programming

Neerja Bhatnagar

CS 203 Programming Languages Fall 2004

Motivation for AOP

• Code continues to grow in size and complexity• Code evolves to become unmodularized, and

hence unclean• Application logic gets intermingled with system

code– For example, business logic of processing

credit card payment intermingled with code that logs the transaction

• AOP aims to improve software design and development via separation of concerns

Conventional Logging• Does not utilize aspects• Utilizes java.util.logging

import java.util.logging.*;… static Logger logger = Logger.getLogger(“Log”);… public void setEmployeeAddress(String address) {

if (name != null) { logger.logp(Level.INFO, “Employee”,

“setEmployeeAddress”, “Address Changed”); employeeAddress = address;

} }

Logging with Aspectsimport org.aspectj.lang.*import java.util.logging.*;public aspect AspectLog { Logger logger = Logger.getLogger(“Log”);

// specify point of execution for

// logging. within matches methods

pointcut logMethods(): execution(* *.*(..)) &&

within(AspectLog);

// begin logging before reaching

// join point before():logMethods() {…

}…

Java code remains unchanged!

public class Employee {

public Employee() {

}

… setEmployeeAddress(String

address) {

}

}

Push functionality related to logging into aspect(s) Application logic remains unchanged.

• AspectJ (Aspects for Java)• AspectC++ (Aspects for C++, may be C)• Weave.NET (Language Independent Aspects)

Frameworks

• Nanning (for Java) (http://nanning.codehaus.org)

• AspectWerkz (for Java) (http://aspectwerkz.codehaus.org)

• JBoss (for Java) (http://www.jboss.org)

• HyperJ (for Java) (www.research.ibm.com/hyperspace/hyperj)

• Others – abc, AspectC#, CLAW, AOP#, AspectDNG

AOP Languages and FrameworksLanguages

AOP Terminology (Buzzwords)

public class Employee { public String employeeName; … public Employee() {…} public void setEmployeeName(String name) { if (name != null) { logger.logp(Level.INFO, "Employee", "setEmployeeName", "Name change"); employeeName = name; } } …}

Crosscutting concern

Join Point

Point Cut

AOP Terminology (Buzzwords), contd.import org.aspectj.lang.*import java.util.logging.*;

public aspect AspectLog { Logger logger = Logger.getLogger(“Log”);

// specify point of execution for// logging. within matches methods pointcut logMethods(): execution(* *.*(..)) && within(AspectLog); // code that actually logs …// begin logging before reaching// join point

before():logMethods() {…

}…

Advice

Aspect

Thank You

Recommended