8
Survey of Aspect- Oriented Programming Neerja Bhatnagar CS 203 Programming Languages Fall 2004

Survey of Aspect-Oriented Programming

  • Upload
    ryann

  • View
    32

  • Download
    4

Embed Size (px)

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

Page 1: Survey of Aspect-Oriented Programming

Survey of Aspect-Oriented Programming

Neerja Bhatnagar

CS 203 Programming Languages Fall 2004

Page 2: Survey of Aspect-Oriented Programming

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

Page 3: Survey of Aspect-Oriented Programming

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;

} }

Page 4: Survey of Aspect-Oriented Programming

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.

Page 5: Survey of Aspect-Oriented Programming

• 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

Page 6: Survey of Aspect-Oriented Programming

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

Page 7: Survey of Aspect-Oriented Programming

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

Page 8: Survey of Aspect-Oriented Programming

Thank You